X Tutup
Skip to content

Commit fe5793e

Browse files
HenryHenry
authored andcommitted
📚1-5
1 parent c50f7d4 commit fe5793e

File tree

9 files changed

+709
-4
lines changed

9 files changed

+709
-4
lines changed

docs/.DS_Store

0 Bytes
Binary file not shown.

docs/data-management/.DS_Store

0 Bytes
Binary file not shown.
2 KB
Binary file not shown.
6 KB
Binary file not shown.

docs/data-management/Redis/reprint/Redis为什么变慢了-常见延迟问题定位与分析.md

Lines changed: 248 additions & 0 deletions
Large diffs are not rendered by default.
0 Bytes
Binary file not shown.

docs/data-structure-algorithms/Double-Pointer.md

Lines changed: 420 additions & 2 deletions
Large diffs are not rendered by default.

docs/data-structure-algorithms/soultion/Array-Solution.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public static int[] twoSum(int[] nums,int target){
2626
}
2727
```
2828
29+
时间复杂度:$O(N)$,其中 N 是数组中的元素数量。对于每一个元素 x,我们可以 $O(1)$ 地寻找 target - x。
30+
31+
空间复杂度:$O(N)$,其中 N 是数组中的元素数量。主要为哈希表的开销。
32+
2933

3034

3135
### [217. 存在重复元素](https://leetcode-cn.com/problems/contains-duplicate/)
@@ -268,9 +272,44 @@ public int maxArea(int[] height){
268272
> 输出:[[-1,-1,2],[-1,0,1]]
269273
> ```
270274
271-
**思路**
272-
275+
**思路**:排序后双指针
273276
277+
```java
278+
public static List<List<Integer>> threeSum(int[] nums) {
279+
//存放结果list
280+
List<List<Integer>> result = new ArrayList<>();
281+
int length = nums.length;
282+
//特例判断
283+
if (length < 3) {
284+
return result;
285+
}
286+
Arrays.sort(nums);
287+
for (int i = 0; i < length; i++) {
288+
//排序后的第一个数字就大于0,就说明没有符合要求的结果
289+
if (nums[i] > 0) break;
290+
291+
//去重
292+
if (i > 0 && nums[i] == nums[i - 1]) continue;
293+
//左右指针
294+
int l = i + 1;
295+
int r = length - 1;
296+
while (l < r) {
297+
int sum = nums[i] + nums[l] + nums[r];
298+
if (sum == 0) {
299+
result.add(Arrays.asList(nums[i], nums[l], nums[r]));
300+
//去重(相同数字的话就移动指针)
301+
while (nums[l] == nums[l + 1]) l++;
302+
while (nums[r] == nums[r - 1]) r--;
303+
//移动指针
304+
l++;
305+
r--;
306+
} else if (sum < 0) l++;
307+
else if (sum > 0) r--;
308+
}
309+
}
310+
return result;
311+
}
312+
```
274313
275314

276315

docs/others/.DS_Store

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
X Tutup