![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode算法
小海子l
keep learning
展开
-
四数之和 | 算法
题目给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满足条件且不重复的四元组。思路四数之和与之前的三数之和、两数之和存在共通性,即:都要确定左边界和右边界在此题中,首先设置第一个数a在数组的最左端,第二个数b在a+1位置,第三个数left在b+1位置,第四个数right在nums.length-1的位置。若left小于right,通过left和ri原创 2021-04-11 15:47:31 · 890 阅读 · 0 评论 -
LeetCode-数组刷题
两数之和 public int[] twoSum(int[] nums, int target) { Map<Integer, Integer> map = new HashMap<>(nums.length); for (int i = 0; i < nums.length; i++) { int n = target - nums[i]; if (map.containsKey(n))原创 2021-03-07 23:37:42 · 103 阅读 · 0 评论