[LeetCode]Two Sum
来源:互联网 发布:中国网络巨头有哪几个 编辑:程序博客网 时间:2024/06/10 03:57
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2
public class Solution { public int[] twoSum(int[] numbers, int target) { int n = numbers.length; int[] arr = new int[2]; for(int i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { if(numbers[i]+numbers[j]==target) { arr[0]=i+1; arr[1]=j+1; } } } return arr; }}
0 0
- 【Leetcode】Two Sum (Sum)
- LeetCode: Two Sum
- LeetCode: Two Sum
- [Leetcode] Two Sum
- LeetCode : Two Sum
- Leetcode: Two Sum
- leetcode 46: Two Sum
- [LeetCode] Two Sum
- LeetCode 1 - Two Sum
- Leetcode : Two Sum
- 【leetcode】Two Sum
- [LeetCode]Two Sum
- leetcode Two Sum
- [Leetcode] Two Sum
- [leetcode] Two Sum
- LeetCode - Two Sum
- leetcode之Two Sum
- LeetCode | Two Sum
- pathForResource返回(null) 无法读取plist文件
- PeopleSoft之切换base language
- Linux下makefile教程
- PHP 开源学习笔记-header函数
- php 设计模式 之 装饰模式
- [LeetCode]Two Sum
- PHP+FFMPEG自动转码H264标准Mp4文件
- Phpcmsv9本地视频转码字段
- php学习
- 《Windows核心编程》——三 内核对象
- php学习笔记(二)面向对象编程
- PHP中的生成XML文件的4种方法
- java“JUC锁”
- snoopy(强大的PHP采集类) 详细介绍