[LeetCode]Two Sum

来源:互联网 发布:国家电网试题软件 编辑:程序博客网 时间:2024/06/16 12:53
题目:点击打开链接

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








0 0
原创粉丝点击