public class Solution
{
public int[] TwoSum(int[] nums, int target)
{
int[] Arr =null;
int a;
int b;
int c = -1;
int d = -1;
for(a=0;a<nums.Length;a++)
{
for(b=0;b<nums.Length;b++)
{
if(nums[a]+nums[b]==target && a<b)
{
Arr= new int[]{a,b};
Console.WriteLine("["+a+","+b+"]");
c= a;
d= b;
if(c==-1&&d==-1)
{
Console.WriteLine("No Exist");
}
}
}
}
return Arr;
}
}
最蠢的遍历。。。
如果不存在两个相加等于target的数字(即没有把地址赋给c,d。c,d仍保持为-1),则显示不存在
题目地址:
https://leetcode-cn.com/problems/two-sum/description/