Skip to content

Commit dcc7f7d

Browse files
committed
Apr-28
1 parent 68a19f1 commit dcc7f7d

18 files changed

+385
-109
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
5454
| [] | [grind75.md](./list/grind75.md) | 75/75 | - |
5555
| [] | [leetcode-top-100-liked.md](./list/leetcode-top-100-liked.md) | 100/100 | - |
5656
| [] | [leetcode101.md](./list/leetcode101.md) | 183/184 | 1 vip |
57-
| [🔲] | [9c-basic.md](./list/9c-basic.md) | 15/128 | 3 vips |
58-
| [🔲] | [endlesscheng.md](./list/endlesscheng.md) | 96/2210 | 4 vips |
57+
| [🔲] | [9c-basic.md](./list/9c-basic.md) | 16/128 | 3 vips |
58+
| [🔲] | [endlesscheng.md](./list/endlesscheng.md) | 102/2209 | 4 vips |
5959

60-
**Solved**: 681 problems
60+
**Solved**: 683 problems
6161

6262
## 类型/Category
6363

@@ -447,11 +447,12 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
447447

448448
## Binary Search
449449

450-
| Link | Problem(77) | Solution | Tag | Time | Space | Ref |
450+
| Link | Problem(78) | Solution | Tag | Time | Space | Ref |
451451
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
452452
| [Leetcode-2968](https://leetcode.com/problems/apply-operations-to-maximize-frequency-score/) | Apply Operations To Maximize Frequency Score | [c++](./leetcode/2968.apply-operations-to-maximize-frequency-score.cpp), [python3](./leetcode/2968.apply-operations-to-maximize-frequency-score.py) | Binary Search | O\(NlogN\) | O\(1\) | - |
453453
| [Leetcode-704](https://leetcode.com/problems/binary-search/) | Binary Search | [c++](./leetcode/704.binary-search.cpp), [python3](./leetcode/704.binary-search.py) | Binary Search | O\(logN\) | O\(1\) | - |
454454
| [Leetcode-2179](https://leetcode.com/problems/count-good-triplets-in-an-array/) | Count Good Triplets In An Array | [c++](./leetcode/2179.count-good-triplets-in-an-array.cpp), [python3](./leetcode/2179.count-good-triplets-in-an-array.py) | Binary Search | O\(NlogN\) | O\(N\) | - |
455+
| [Leetcode-2824](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/) | Count Pairs Whose Sum Is Less Than Target | [c++](./leetcode/2824.count-pairs-whose-sum-is-less-than-target.cpp), [python3](./leetcode/2824.count-pairs-whose-sum-is-less-than-target.py) | Binary Search | O\(NlogN\) | O\(1\) | - |
455456
| [Leetcode-2302](https://leetcode.com/problems/count-subarrays-with-score-less-than-k/) | Count Subarrays With Score Less Than K | [c++](./leetcode/2302.count-subarrays-with-score-less-than-k.cpp), [python3](./leetcode/2302.count-subarrays-with-score-less-than-k.py) | Binary Search | O\(N\) | O\(1\) | - |
456457
| [Leetcode-3261](https://leetcode.com/problems/count-substrings-that-satisfy-k-constraint-ii/) | Count Substrings That Satisfy K Constraint II | [c++](./leetcode/3261.count-substrings-that-satisfy-k-constraint-ii.cpp), [python3](./leetcode/3261.count-substrings-that-satisfy-k-constraint-ii.py) | Binary Search | O\(N \+ Q\) | O\(N\) | - |
457458
| [Leetcode-2563](https://leetcode.com/problems/count-the-number-of-fair-pairs/) | Count The Number Of Fair Pairs | [c++](./leetcode/2563.count-the-number-of-fair-pairs.cpp), [python3](./leetcode/2563.count-the-number-of-fair-pairs.py) | Binary Search | O\(NlogN\) | O\(1\) | - |
@@ -848,14 +849,15 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
848849

849850
## Two Pointers
850851

851-
| Link | Problem(47) | Solution | Tag | Time | Space | Ref |
852+
| Link | Problem(49) | Solution | Tag | Time | Space | Ref |
852853
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
853854
| [Leetcode-15](https://leetcode.com/problems/3sum/) | 3Sum | [c++](./leetcode/15.3sum.cpp), [python3](./leetcode/15.3sum.py) | Two Pointers | O\(N^2\) | O\(1\) | - |
854855
| [Leetcode-18](https://leetcode.com/problems/4sum/) | 4Sum | [c++](./leetcode/18.4sum.cpp), [python3](./leetcode/18.4sum.py) | Two Pointers | O\(N^3\) | O\(1\) | - |
855856
| [Leetcode-870](https://leetcode.com/problems/advantage-shuffle/) | Advantage Shuffle | [c++](./leetcode/870.advantage-shuffle.cpp), [python3](./leetcode/870.advantage-shuffle.py) | Two Pointers | O\(NlogN\) | O\(N\) | - |
856857
| [Leetcode-2460](https://leetcode.com/problems/apply-operations-to-an-array/) | Apply Operations To An Array | [c++](./leetcode/2460.apply-operations-to-an-array.cpp), [python3](./leetcode/2460.apply-operations-to-an-array.py) | Two Pointers | O\(N\) | O\(1\) | - |
857858
| [Leetcode-455](https://leetcode.com/problems/assign-cookies/) | Assign Cookies | [c++](./leetcode/455.assign-cookies.cpp), [python3](./leetcode/455.assign-cookies.py) | Two Pointers | O\(NlogN\) | O\(1\) | - |
858859
| [Leetcode-696](https://leetcode.com/problems/count-binary-substrings/) | Count Binary Substrings | [c++](./leetcode/696.count-binary-substrings.cpp), [python3](./leetcode/696.count-binary-substrings.py) | Two Pointers | O\(N\) | O\(1\) | - |
860+
| [Leetcode-2824](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/) | Count Pairs Whose Sum Is Less Than Target | [c++](./leetcode/2824.count-pairs-whose-sum-is-less-than-target.cpp), [python3](./leetcode/2824.count-pairs-whose-sum-is-less-than-target.py) | Two Pointers | O\(NlogN\) | O\(1\) | - |
859861
| [Leetcode-2563](https://leetcode.com/problems/count-the-number-of-fair-pairs/) | Count The Number Of Fair Pairs | [c++](./leetcode/2563.count-the-number-of-fair-pairs.cpp), [python3](./leetcode/2563.count-the-number-of-fair-pairs.py) | Two Pointers | O\(NlogN\) | O\(1\) | - |
860862
| [Leetcode-295](https://leetcode.com/problems/find-median-from-data-stream/) | Find Median From Data Stream | [c++](./leetcode/295.find-median-from-data-stream.cpp), [python3](./leetcode/295.find-median-from-data-stream.py) | Two Pointers | O\(logN\) | O\(N\) | - |
861863
| [Leetcode-287](https://leetcode.com/problems/find-the-duplicate-number/) | Find The Duplicate Number | [c++](./leetcode/287.find-the-duplicate-number.cpp), [python3](./leetcode/287.find-the-duplicate-number.py) | Two Pointers | O\(N\) | O\(1\) | - |
@@ -884,6 +886,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
884886
| [Leetcode-148](https://leetcode.com/problems/sort-list/) | Sort List | [c++](./leetcode/148.sort-list.cpp), [python3](./leetcode/148.sort-list.py) | Two Pointers | O\(NlogN\) | O\(logN\) | - |
885887
| [Leetcode-977](https://leetcode.com/problems/squares-of-a-sorted-array/) | Squares Of A Sorted Array | [c++](./leetcode/977.squares-of-a-sorted-array.cpp), [python3](./leetcode/977.squares-of-a-sorted-array.py) | Two Pointers | O\(N\) | O\(1\) | - |
886888
| [Leetcode-633](https://leetcode.com/problems/sum-of-square-numbers/) | Sum Of Square Numbers | [c++](./leetcode/633.sum-of-square-numbers.cpp), [python3](./leetcode/633.sum-of-square-numbers.py) | Two Pointers | O\(N\) | O\(1\) | - |
889+
| [Leetcode-1471](https://leetcode.com/problems/the-k-strongest-values-in-an-array/) | The K Strongest Values In An Array | [c++](./leetcode/1471.the-k-strongest-values-in-an-array.cpp), [python3](./leetcode/1471.the-k-strongest-values-in-an-array.py) | Two Pointers | O\(NlogN\) | O\(1\) | - |
887890
| [Leetcode-42](https://leetcode.com/problems/trapping-rain-water/) | Trapping Rain Water | [c++](./leetcode/42.trapping-rain-water.cpp), [python3](./leetcode/42.trapping-rain-water.py) | Two Pointers | O\(N\) | O\(N\) | - |
888891
| [Leetcode-167](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | Two Sum Ii Input Array Is Sorted | [c++](./leetcode/167.two-sum-ii-input-array-is-sorted.cpp), [python3](./leetcode/167.two-sum-ii-input-array-is-sorted.py) | Two Pointers | O\(N\) | O\(1\) | - |
889892
| [Leetcode-653](https://leetcode.com/problems/two-sum-iv-input-is-a-bst/) | Two Sum Iv Input Is A Bst | [c++](./leetcode/653.two-sum-iv-input-is-a-bst.cpp), [python3](./leetcode/653.two-sum-iv-input-is-a-bst.py) | Two Pointers | O\(NH\) | O\(H\) | - |
@@ -994,7 +997,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
994997

995998
## Sorting
996999

997-
| Link | Problem(74) | Solution | Tag | Time | Space | Ref |
1000+
| Link | Problem(76) | Solution | Tag | Time | Space | Ref |
9981001
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
9991002
| [Leetcode-15](https://leetcode.com/problems/3sum/) | 3Sum | [c++](./leetcode/15.3sum.cpp), [python3](./leetcode/15.3sum.py) | Sorting | O\(N^2\) | O\(1\) | - |
10001003
| [Leetcode-18](https://leetcode.com/problems/4sum/) | 4Sum | [c++](./leetcode/18.4sum.cpp), [python3](./leetcode/18.4sum.py) | Sorting | O\(N^3\) | O\(1\) | - |
@@ -1010,6 +1013,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
10101013
| [Leetcode-220](https://leetcode.com/problems/contains-duplicate-iii/) | Contains Duplicate III | [c++](./leetcode/220.contains-duplicate-iii.cpp), [python3](./leetcode/220.contains-duplicate-iii.py) | Sorting | O\(N\) | O\(N\) | - |
10111014
| [Leetcode-3169](https://leetcode.com/problems/count-days-without-meetings/) | Count Days Without Meetings | [c++](./leetcode/3169.count-days-without-meetings.cpp), [python3](./leetcode/3169.count-days-without-meetings.py) | Sorting | O\(NlogN\) | O\(N\) | - |
10121015
| [Leetcode-2179](https://leetcode.com/problems/count-good-triplets-in-an-array/) | Count Good Triplets In An Array | [c++](./leetcode/2179.count-good-triplets-in-an-array.cpp), [python3](./leetcode/2179.count-good-triplets-in-an-array.py) | Sorting | O\(NlogN\) | O\(N\) | - |
1016+
| [Leetcode-2824](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/) | Count Pairs Whose Sum Is Less Than Target | [c++](./leetcode/2824.count-pairs-whose-sum-is-less-than-target.cpp), [python3](./leetcode/2824.count-pairs-whose-sum-is-less-than-target.py) | Sorting | O\(NlogN\) | O\(1\) | - |
10131017
| [Leetcode-2563](https://leetcode.com/problems/count-the-number-of-fair-pairs/) | Count The Number Of Fair Pairs | [c++](./leetcode/2563.count-the-number-of-fair-pairs.cpp), [python3](./leetcode/2563.count-the-number-of-fair-pairs.py) | Sorting | O\(NlogN\) | O\(1\) | - |
10141018
| [Leetcode-210](https://leetcode.com/problems/course-schedule-ii/) | Course Schedule II | [c++](./leetcode/210.course-schedule-ii.cpp), [python3](./leetcode/210.course-schedule-ii.py) | Sorting | O\(E\+V\) | O\(E\+V\) | - |
10151019
| [Leetcode-1943](https://leetcode.com/problems/describe-the-painting/) | Describe The Painting | [c++](./leetcode/1943.describe-the-painting.cpp), [python3](./leetcode/1943.describe-the-painting.py) | Sorting | O\(NlogN\) | O\(N\) | - |
@@ -1062,6 +1066,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
10621066
| [Leetcode-75](https://leetcode.com/problems/sort-colors/) | Sort Colors | [c++](./leetcode/75.sort-colors.cpp), [python3](./leetcode/75.sort-colors.py) | Sorting | O\(N\) | O\(1\) | - |
10631067
| [Leetcode-148](https://leetcode.com/problems/sort-list/) | Sort List | [c++](./leetcode/148.sort-list.cpp), [python3](./leetcode/148.sort-list.py) | Sorting | O\(NlogN\) | O\(logN\) | - |
10641068
| [Leetcode-977](https://leetcode.com/problems/squares-of-a-sorted-array/) | Squares Of A Sorted Array | [c++](./leetcode/977.squares-of-a-sorted-array.cpp), [python3](./leetcode/977.squares-of-a-sorted-array.py) | Sorting | O\(N\) | O\(1\) | - |
1069+
| [Leetcode-1471](https://leetcode.com/problems/the-k-strongest-values-in-an-array/) | The K Strongest Values In An Array | [c++](./leetcode/1471.the-k-strongest-values-in-an-array.cpp), [python3](./leetcode/1471.the-k-strongest-values-in-an-array.py) | Sorting | O\(NlogN\) | O\(1\) | - |
10651070
| [Leetcode-242](https://leetcode.com/problems/valid-anagram/) | Valid Anagram | [c++](./leetcode/242.valid-anagram.cpp), [python3](./leetcode/242.valid-anagram.py) | Sorting | O\(N\) | O\(1\) | - |
10661071
| [Leetcode-324](https://leetcode.com/problems/wiggle-sort-ii/) | Wiggle Sort II | [c++](./leetcode/324.wiggle-sort-ii.cpp), [python3](./leetcode/324.wiggle-sort-ii.py) | Sorting | \- | \- | - |
10671072
| [Leetcode-3362](https://leetcode.com/problems/zero-array-transformation-iii/) | Zero Array Transformation III | [c++](./leetcode/3362.zero-array-transformation-iii.cpp), [python3](./leetcode/3362.zero-array-transformation-iii.py) | Sorting | O\(NlogN\) | O\(N\) | - |
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Tag: Array, Two Pointers, Sorting
2+
// Time: O(NlogN)
3+
// Space: O(1)
4+
// Ref: -
5+
// Note: -
6+
7+
// Given an array of integers arr and an integer k.
8+
// A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the centre of the array.
9+
// If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j].
10+
// Return a list of the strongest k values in the array. return the answer in any arbitrary order.
11+
// The centre is the middle value in an ordered integer list. More formally, if the length of the list is n, the centre is the element in position ((n - 1) / 2) in the sorted list (0-indexed).
12+
//
13+
// For arr = [6, -3, 7, 2, 11], n = 5 and the centre is obtained by sorting the array arr = [-3, 2, 6, 7, 11] and the centre is arr[m] where m = ((5 - 1) / 2) = 2. The centre is 6.
14+
// For arr = [-7, 22, 17, 3], n = 4 and the centre is obtained by sorting the array arr = [-7, 3, 17, 22] and the centre is arr[m] where m = ((4 - 1) / 2) = 1. The centre is 3.
15+
//
16+
//
17+
//
18+
//  
19+
//
20+
//
21+
//  
22+
//
23+
//  
24+
//  
25+
//
26+
//
27+
//
28+
//
29+
//
30+
//  
31+
// Example 1:
32+
//
33+
// Input: arr = [1,2,3,4,5], k = 2
34+
// Output: [5,1]
35+
// Explanation: Centre is 3, the elements of the array sorted by the strongest are [5,1,4,2,3]. The strongest 2 elements are [5, 1]. [1, 5] is also accepted answer.
36+
// Please note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5 > 1.
37+
//
38+
// Example 2:
39+
//
40+
// Input: arr = [1,1,3,5,5], k = 2
41+
// Output: [5,5]
42+
// Explanation: Centre is 3, the elements of the array sorted by the strongest are [5,5,1,1,3]. The strongest 2 elements are [5, 5].
43+
//
44+
// Example 3:
45+
//
46+
// Input: arr = [6,7,11,7,6,8], k = 5
47+
// Output: [11,8,6,6,7]
48+
// Explanation: Centre is 7, the elements of the array sorted by the strongest are [11,8,6,6,7,7].
49+
// Any permutation of [11,8,6,6,7] is accepted.
50+
//
51+
//  
52+
// Constraints:
53+
//
54+
// 1 <= arr.length <= 105
55+
// -105 <= arr[i] <= 105
56+
// 1 <= k <= arr.length
57+
//
58+
//
59+
60+
class Solution {
61+
public:
62+
vector<int> getStrongest(vector<int>& arr, int k) {
63+
int n = arr.size();
64+
sort(arr.begin(), arr.end());
65+
int l = 0;
66+
int r = n - 1;
67+
vector<int> res;
68+
int mid = arr[(n - 1) / 2];
69+
while (l <= r && res.size() < k) {
70+
if (mid - arr[l] > arr[r] - mid) {
71+
res.push_back(arr[l]);
72+
l += 1;
73+
} else {
74+
res.push_back(arr[r]);
75+
r -= 1;
76+
}
77+
}
78+
79+
return res;
80+
}
81+
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Tag: Array, Two Pointers, Sorting
2+
# Time: O(NlogN)
3+
# Space: O(1)
4+
# Ref: -
5+
# Note: -
6+
7+
# Given an array of integers arr and an integer k.
8+
# A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the centre of the array.
9+
# If |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j].
10+
# Return a list of the strongest k values in the array. return the answer in any arbitrary order.
11+
# The centre is the middle value in an ordered integer list. More formally, if the length of the list is n, the centre is the element in position ((n - 1) / 2) in the sorted list (0-indexed).
12+
#
13+
# For arr = [6, -3, 7, 2, 11], n = 5 and the centre is obtained by sorting the array arr = [-3, 2, 6, 7, 11] and the centre is arr[m] where m = ((5 - 1) / 2) = 2. The centre is 6.
14+
# For arr = [-7, 22, 17, 3], n = 4 and the centre is obtained by sorting the array arr = [-7, 3, 17, 22] and the centre is arr[m] where m = ((4 - 1) / 2) = 1. The centre is 3.
15+
#
16+
#
17+
#
18+
#  
19+
#
20+
#
21+
#  
22+
#
23+
#  
24+
#  
25+
#
26+
#
27+
#
28+
#
29+
#
30+
#  
31+
# Example 1:
32+
#
33+
# Input: arr = [1,2,3,4,5], k = 2
34+
# Output: [5,1]
35+
# Explanation: Centre is 3, the elements of the array sorted by the strongest are [5,1,4,2,3]. The strongest 2 elements are [5, 1]. [1, 5] is also accepted answer.
36+
# Please note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5 > 1.
37+
#
38+
# Example 2:
39+
#
40+
# Input: arr = [1,1,3,5,5], k = 2
41+
# Output: [5,5]
42+
# Explanation: Centre is 3, the elements of the array sorted by the strongest are [5,5,1,1,3]. The strongest 2 elements are [5, 5].
43+
#
44+
# Example 3:
45+
#
46+
# Input: arr = [6,7,11,7,6,8], k = 5
47+
# Output: [11,8,6,6,7]
48+
# Explanation: Centre is 7, the elements of the array sorted by the strongest are [11,8,6,6,7,7].
49+
# Any permutation of [11,8,6,6,7] is accepted.
50+
#
51+
#  
52+
# Constraints:
53+
#
54+
# 1 <= arr.length <= 105
55+
# -105 <= arr[i] <= 105
56+
# 1 <= k <= arr.length
57+
#
58+
#
59+
60+
class Solution:
61+
def getStrongest(self, arr: List[int], k: int) -> List[int]:
62+
n = len(arr)
63+
l = 0
64+
r = n - 1
65+
arr.sort()
66+
res = []
67+
mid = arr[(n - 1) // 2]
68+
while l <= r and len(res) < k:
69+
if mid - arr[l] > arr[r] - mid:
70+
res.append(arr[l])
71+
l += 1
72+
else:
73+
res.append(arr[r])
74+
r -= 1
75+
76+
return res

leetcode/15.3sum.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,28 @@ class Solution {
4545
sort(nums.begin(), nums.end());
4646
vector<vector<int>> res;
4747

48-
for (int i = 0; i < n; i++) {
49-
if (i > 0 && nums[i] == nums[i - 1]) {
48+
for (int k = 2; k < n; k++) {
49+
if (k + 1 < n && nums[k] == nums[k + 1]) {
5050
continue;
5151
}
52-
int target = -nums[i];
53-
int left = i + 1;
54-
int right = n - 1;
55-
while (left < right) {
56-
if (nums[left] + nums[right] == target) {
57-
res.push_back({nums[left], nums[right], nums[i]});
58-
while (left < right && nums[right] == nums[right - 1]) {
59-
right--;
52+
int target = -nums[k];
53+
int l = 0;
54+
int r = k - 1;
55+
while (l < r) {
56+
if (nums[l] + nums[r] == target) {
57+
res.push_back({nums[l], nums[r], nums[k]});
58+
while (l < r && nums[r] == nums[r - 1]) {
59+
r--;
6060
}
61-
while (left < right && nums[left] == nums[left + 1]) {
62-
left++;
61+
while (l < r && nums[l] == nums[l + 1]) {
62+
l++;
6363
}
64-
left++;
65-
right--;
66-
} else if (nums[left] + nums[right] > target) {
67-
right--;
64+
l++;
65+
r--;
66+
} else if (nums[l] + nums[r] > target) {
67+
r--;
6868
} else {
69-
left++;
69+
l++;
7070
}
7171
}
7272
}

leetcode/15.3sum.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,25 @@ def threeSum(self, nums: List[int]) -> List[List[int]]:
4343
n = len(nums)
4444
nums.sort()
4545
res = []
46-
for i in range(n):
47-
if i > 0 and nums[i] == nums[i] - 1:
46+
for k in range(2, n):
47+
if k + 1 < n and nums[k] == nums[k + 1]:
4848
continue
49-
50-
target = -nums[i]
51-
52-
left = i + 1
53-
right = n - 1
54-
while left < right:
55-
if nums[left] + nums[right] == target:
56-
res.append([nums[left], nums[right], nums[i]])
57-
while left < right and nums[right] == nums[right - 1]:
58-
right -= 1
59-
while left < right and nums[left] == nums[left + 1]:
60-
left += 1
61-
left += 1
62-
right -= 1
63-
64-
if nums[left] + nums[right] > target:
65-
right -= 1
49+
target = -nums[k]
50+
l = 0
51+
r = k - 1
52+
while l < r:
53+
if nums[l] + nums[r] == target:
54+
res.append([nums[l], nums[r], nums[k]])
55+
while l < r and nums[l + 1] == nums[l]:
56+
l += 1
57+
while l < r and nums[r - 1] == nums[r]:
58+
r -= 1
59+
l += 1
60+
r -= 1
61+
elif nums[l] + nums[r] > target:
62+
r -= 1
6663
else:
67-
left += 1
64+
l += 1
6865
return res
6966

7067
class Solution:

0 commit comments

Comments
 (0)