您的位置:首页 > 编程语言 > C#

【LeetCode】(C#)1. Two Sum(Easy)

2017-12-27 11:17 351 查看
Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.
public int[] TwoSum(int[] nums, int target) {
int[] result=new int[2];
for(int i=0;i<nums.Length;i++)
{
for(int j=0;j<nums.Length;j++)
{
if(i!=j)
{
if(nums[i]+nums[j]==target)
return new int [] {i,j};
}
}
}
return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: