1. Two Sum

public class Solution {
    public int[] TwoSum(int[] nums, int target) {
        if(nums == null || nums.Length < 1)
        {
            return null;
        }
        for(int i = 0; i < nums.Length; i++)
        {
            for(int j = i + 1; j < nums.Length; j++)
            {
                if(nums[i] + nums[j] == target)
                {
                    return new int[2]{i, j};
                }
            }
        }
        return null;
    }
}

你可能感兴趣的:(1. Two Sum)