钱多事少离家近 level
绿盟科技_研发工程师 identity
获赞
1180
粉丝
45
关注
30
看过 TA
178
西安电子科技大学
2021
Java
IP属地:广东
我太南了
私信
关注
2019-09-18 12:06
绿盟科技_研发工程师
0 点赞 评论 收藏
分享
2019-09-17 22:11
绿盟科技_研发工程师
0 点赞 评论 收藏
分享
2019-09-15 17:35
绿盟科技_研发工程师
Leetcode每日一题_18    public List<List<Integer>> fourSum(int[] nums, int target) {        List<List<Integer>> ans = new ArrayList();int len = nums.length;Arrays.sort(nums);if (nums == null || len < 4)return ans;for (int i = 0; i < len - 3; i++) {if (i > 0 && nums[i] == nums[i - 1])continue;for (int j = i + 1; j < len - 2; j++) {if (j > i + 1 && nums[j] == nums[j - 1])continue;int L = j + 1;int R = len - 1;while (L < R) {int sum = nums[i] + nums[j] + nums[L] + nums[R];if (sum == target) {ans.add(Arrays.asList(nums[i], nums[j], nums[L], nums[R]));while (L < R && nums[L] == nums[L + 1])L++;while (L < R && nums[R] == nums[R - 1])R--;L++;R--;} else if (sum > target)R--;else if (sum < target)L++;}}}return ans;    }
投递思源智通等公司6个岗位
0 点赞 评论 收藏
分享

创作者周榜

更多
关注他的用户也关注了:
牛客网
牛客企业服务