Skip to content

Commit 8648b2b

Browse files
committed
May-6
1 parent 4f803bc commit 8648b2b

6 files changed

+264
-8
lines changed

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
4141
| [51%] | [leetcode-google.md](./list/leetcode-google.md) | 241/471 | 2 vips |
4242
| [52%] | [leetcode-discuss.md](./list/leetcode-discuss.md) | 45/85 | 1 vip |
4343
| [53%] | [leetcode-75.md](./list/leetcode-75.md) | 40/75 | - |
44-
| [54%] | [leetcode-topics.md](./list/leetcode-topics.md) | 79/144 | - |
44+
| [55%] | [leetcode-topics.md](./list/leetcode-topics.md) | 80/144 | - |
4545
| [86%] | [leetcode-top-interview-150.md](./list/leetcode-top-interview-150.md) | 130/150 | - |
4646
| [95%] | [neetcode150.md](./list/neetcode150.md) | 143/150 | - |
4747
| [] | [9c-advanced.md](./list/9c-advanced.md) | 75/93 | 18 vips |
@@ -55,9 +55,9 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
5555
| [] | [leetcode-top-100-liked.md](./list/leetcode-top-100-liked.md) | 100/100 | - |
5656
| [] | [leetcode101.md](./list/leetcode101.md) | 183/184 | 1 vip |
5757
| [🔲] | [9c-basic.md](./list/9c-basic.md) | 16/128 | 3 vips |
58-
| [🔲] | [endlesscheng.md](./list/endlesscheng.md) | 111/2209 | 4 vips |
58+
| [🔲] | [endlesscheng.md](./list/endlesscheng.md) | 112/2209 | 4 vips |
5959

60-
**Solved**: 694 problems
60+
**Solved**: 696 problems
6161

6262
## 类型/Category
6363

@@ -218,12 +218,13 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
218218

219219
## Simulation
220220

221-
| Link | Problem(28) | Solution | Tag | Time | Space | Ref |
221+
| Link | Problem(29) | Solution | Tag | Time | Space | Ref |
222222
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
223223
| [Leetcode-67](https://leetcode.com/problems/add-binary/) | Add Binary | [c++](./leetcode/67.add-binary.cpp), [python3](./leetcode/67.add-binary.py) | Simulation | O\(M\+N\) | O\(1\) | - |
224224
| [Leetcode-415](https://leetcode.com/problems/add-strings/) | Add Strings | [c++](./leetcode/415.add-strings.cpp), [python3](./leetcode/415.add-strings.py) | Simulation | O\(N\) | O\(1\) | - |
225225
| [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) | Simulation | O\(N\) | O\(1\) | - |
226226
| [Leetcode-735](https://leetcode.com/problems/asteroid-collision/) | Asteroid Collision | [c++](./leetcode/735.asteroid-collision.cpp), [python3](./leetcode/735.asteroid-collision.py) | Simulation | O\(N\) | O\(N\) | - |
227+
| [Leetcode-1920](https://leetcode.com/problems/build-array-from-permutation/) | Build Array From Permutation | [c++](./leetcode/1920.build-array-from-permutation.cpp), [python3](./leetcode/1920.build-array-from-permutation.py) | Simulation | O\(N\) | O\(1\) | - |
227228
| [Leetcode-1094](https://leetcode.com/problems/car-pooling/) | Car Pooling | [c++](./leetcode/1094.car-pooling.cpp), [python3](./leetcode/1094.car-pooling.py) | Simulation | O\(NlogN\) | O\(N\) | - |
228229
| [Leetcode-3174](https://leetcode.com/problems/clear-digits/) | Clear Digits | [c++](./leetcode/3174.clear-digits.cpp), [python3](./leetcode/3174.clear-digits.py) | Simulation | O\(N\) | O\(N\) | - |
229230
| [Leetcode-3160](https://leetcode.com/problems/find-the-number-of-distinct-colors-among-the-balls/) | Find The Number Of Distinct Colors Among The Balls | [c++](./leetcode/3160.find-the-number-of-distinct-colors-among-the-balls.cpp), [python3](./leetcode/3160.find-the-number-of-distinct-colors-among-the-balls.py) | Simulation | O\(N\) | O\(N\) | - |
@@ -456,7 +457,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
456457

457458
## Binary Search
458459

459-
| Link | Problem(80) | Solution | Tag | Time | Space | Ref |
460+
| Link | Problem(81) | Solution | Tag | Time | Space | Ref |
460461
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
461462
| [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\) | - |
462463
| [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\) | - |
@@ -509,6 +510,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
509510
| [Leetcode-731](https://leetcode.com/problems/my-calendar-ii/) | My Calendar II | [c++](./leetcode/731.my-calendar-ii.cpp), [python3](./leetcode/731.my-calendar-ii.py) | Binary Search | O\(N\) | O\(N\) | - |
510511
| [Leetcode-732](https://leetcode.com/problems/my-calendar-iii/) | My Calendar III | [c++](./leetcode/732.my-calendar-iii.cpp), [python3](./leetcode/732.my-calendar-iii.py) | Binary Search | O\(NlogN\) | O\(N\) | - |
511512
| [Leetcode-2251](https://leetcode.com/problems/number-of-flowers-in-full-bloom/) | Number Of Flowers In Full Bloom | [c++](./leetcode/2251.number-of-flowers-in-full-bloom.cpp), [python3](./leetcode/2251.number-of-flowers-in-full-bloom.py) | Binary Search | O\(NlogN \+ MlogM\) | O\(N \+ M\) | - |
513+
| [Leetcode-1498](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/) | Number Of Subsequences That Satisfy The Given Sum Condition | [c++](./leetcode/1498.number-of-subsequences-that-satisfy-the-given-sum-condition.cpp), [python3](./leetcode/1498.number-of-subsequences-that-satisfy-the-given-sum-condition.py) | Binary Search | O\(NlogN\) | O\(1\) | - |
512514
| [Leetcode-1631](https://leetcode.com/problems/path-with-minimum-effort/) | Path With Minimum Effort | [c++](./leetcode/1631.path-with-minimum-effort.cpp), [python3](./leetcode/1631.path-with-minimum-effort.py) | Binary Search | O\(NMlogNM\) | O\(NM\) | - |
513515
| [Leetcode-852](https://leetcode.com/problems/peak-index-in-a-mountain-array/) | Peak Index In A Mountain Array | [c++](./leetcode/852.peak-index-in-a-mountain-array.cpp), [python3](./leetcode/852.peak-index-in-a-mountain-array.py) | Binary Search | O\(logN\) | O\(1\) | - |
514516
| [Leetcode-528](https://leetcode.com/problems/random-pick-with-weight/) | Random Pick With Weight | [c++](./leetcode/528.random-pick-with-weight.cpp), [python3](./leetcode/528.random-pick-with-weight.py) | Binary Search | O\(NlogN\) | O\(N\) | - |
@@ -864,7 +866,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
864866

865867
## Two Pointers
866868

867-
| Link | Problem(57) | Solution | Tag | Time | Space | Ref |
869+
| Link | Problem(58) | Solution | Tag | Time | Space | Ref |
868870
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
869871
| [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\) | - |
870872
| [Leetcode-16](https://leetcode.com/problems/3sum-closest/) | 3Sum Closest | [c++](./leetcode/16.3sum-closest.cpp), [python3](./leetcode/16.3sum-closest.py) | Two Pointers | O\(N^2\) | O\(1\) | - |
@@ -894,6 +896,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
894896
| [Leetcode-876](https://leetcode.com/problems/middle-of-the-linked-list/) | Middle Of The Linked List | [c++](./leetcode/876.middle-of-the-linked-list.cpp), [python3](./leetcode/876.middle-of-the-linked-list.py) | Two Pointers | O\(N\) | O\(1\) | - |
895897
| [Leetcode-1750](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/) | Minimum Length Of String After Deleting Similar Ends | [c++](./leetcode/1750.minimum-length-of-string-after-deleting-similar-ends.cpp), [python3](./leetcode/1750.minimum-length-of-string-after-deleting-similar-ends.py) | Two Pointers | O\(N\) | O\(1\) | - |
896898
| [Leetcode-1040](https://leetcode.com/problems/moving-stones-until-consecutive-ii/) | Moving Stones Until Consecutive II | [c++](./leetcode/1040.moving-stones-until-consecutive-ii.cpp), [python3](./leetcode/1040.moving-stones-until-consecutive-ii.py) | Two Pointers | O\(NlogN\) | O\(1\) | - |
899+
| [Leetcode-1498](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/) | Number Of Subsequences That Satisfy The Given Sum Condition | [c++](./leetcode/1498.number-of-subsequences-that-satisfy-the-given-sum-condition.cpp), [python3](./leetcode/1498.number-of-subsequences-that-satisfy-the-given-sum-condition.py) | Two Pointers | O\(NlogN\) | O\(1\) | - |
897900
| [Leetcode-1577](https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers/) | Number Of Ways Where Square Of Number Is Equal To Product Of Two Numbers | [c++](./leetcode/1577.number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers.cpp), [python3](./leetcode/1577.number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers.py) | Two Pointers | O\(NM\) | O\(N \+ M\) | - |
898901
| [Leetcode-234](https://leetcode.com/problems/palindrome-linked-list/) | Palindrome Linked List | [c++](./leetcode/234.palindrome-linked-list.cpp), [python3](./leetcode/234.palindrome-linked-list.py) | Two Pointers | O\(N\) | O\(1\) | - |
899902
| [Leetcode-647](https://leetcode.com/problems/palindromic-substrings/) | Palindromic Substrings | [c++](./leetcode/647.palindromic-substrings.cpp), [python3](./leetcode/647.palindromic-substrings.py) | Two Pointers | O\(N^2\) | O\(1\) | - |
@@ -1020,7 +1023,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
10201023

10211024
## Sorting
10221025

1023-
| Link | Problem(80) | Solution | Tag | Time | Space | Ref |
1026+
| Link | Problem(81) | Solution | Tag | Time | Space | Ref |
10241027
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
10251028
| [Leetcode-15](https://leetcode.com/problems/3sum/) | 3Sum | [c++](./leetcode/15.3sum.cpp), [python3](./leetcode/15.3sum.py) | Sorting | O\(N^2\) | O\(1\) | - |
10261029
| [Leetcode-16](https://leetcode.com/problems/3sum-closest/) | 3Sum Closest | [c++](./leetcode/16.3sum-closest.cpp), [python3](./leetcode/16.3sum-closest.py) | Sorting | O\(N^2\) | O\(1\) | - |
@@ -1083,6 +1086,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
10831086
| [Leetcode-1040](https://leetcode.com/problems/moving-stones-until-consecutive-ii/) | Moving Stones Until Consecutive II | [c++](./leetcode/1040.moving-stones-until-consecutive-ii.cpp), [python3](./leetcode/1040.moving-stones-until-consecutive-ii.py) | Sorting | O\(NlogN\) | O\(1\) | - |
10841087
| [Leetcode-435](https://leetcode.com/problems/non-overlapping-intervals/) | Non Overlapping Intervals | [c++](./leetcode/435.non-overlapping-intervals.cpp), [python3](./leetcode/435.non-overlapping-intervals.py) | Sorting | O\(NlogN\) | O\(1\) | - |
10851088
| [Leetcode-2251](https://leetcode.com/problems/number-of-flowers-in-full-bloom/) | Number Of Flowers In Full Bloom | [c++](./leetcode/2251.number-of-flowers-in-full-bloom.cpp), [python3](./leetcode/2251.number-of-flowers-in-full-bloom.py) | Sorting | O\(NlogN \+ MlogM\) | O\(N \+ M\) | - |
1089+
| [Leetcode-1498](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/) | Number Of Subsequences That Satisfy The Given Sum Condition | [c++](./leetcode/1498.number-of-subsequences-that-satisfy-the-given-sum-condition.cpp), [python3](./leetcode/1498.number-of-subsequences-that-satisfy-the-given-sum-condition.py) | Sorting | O\(NlogN\) | O\(1\) | - |
10861090
| [Leetcode-1976](https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/) | Number Of Ways To Arrive At Destination | [c++](./leetcode/1976.number-of-ways-to-arrive-at-destination.cpp), [python3](./leetcode/1976.number-of-ways-to-arrive-at-destination.py) | Sorting | O\(\(E \+ V\)logV\) | O\(E \+ V\) | - |
10871091
| [Leetcode-2551](https://leetcode.com/problems/put-marbles-in-bags/) | Put Marbles In Bags | [c++](./leetcode/2551.put-marbles-in-bags.cpp), [python3](./leetcode/2551.put-marbles-in-bags.py) | Sorting | O\(N\) | O\(N\) | - |
10881092
| [Leetcode-406](https://leetcode.com/problems/queue-reconstruction-by-height/) | Queue Reconstruction By Height | [c++](./leetcode/406.queue-reconstruction-by-height.cpp), [python3](./leetcode/406.queue-reconstruction-by-height.py) | Sorting | O\(NlogN\) | O\(1\) | - |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Tag: Array, Two Pointers, Binary Search, Sorting
2+
// Time: O(NlogN)
3+
// Space: O(1)
4+
// Ref: -
5+
// Note: -
6+
7+
// You are given an array of integers nums and an integer target.
8+
// Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 109 + 7.
9+
//  
10+
// Example 1:
11+
//
12+
// Input: nums = [3,5,6,7], target = 9
13+
// Output: 4
14+
// Explanation: There are 4 subsequences that satisfy the condition.
15+
// [3] -> Min value + max value <= target (3 + 3 <= 9)
16+
// [3,5] -> (3 + 5 <= 9)
17+
// [3,5,6] -> (3 + 6 <= 9)
18+
// [3,6] -> (3 + 6 <= 9)
19+
//
20+
// Example 2:
21+
//
22+
// Input: nums = [3,3,6,8], target = 10
23+
// Output: 6
24+
// Explanation: There are 6 subsequences that satisfy the condition. (nums can have repeated numbers).
25+
// [3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]
26+
//
27+
// Example 3:
28+
//
29+
// Input: nums = [2,3,3,4,6,7], target = 12
30+
// Output: 61
31+
// Explanation: There are 63 non-empty subsequences, two of them do not satisfy the condition ([6,7], [7]).
32+
// Number of valid subsequences (63 - 2 = 61).
33+
//
34+
//  
35+
// Constraints:
36+
//
37+
// 1 <= nums.length <= 105
38+
// 1 <= nums[i] <= 106
39+
// 1 <= target <= 106
40+
//
41+
//
42+
43+
class Solution {
44+
public:
45+
int numSubseq(vector<int>& nums, int target) {
46+
int mod = 1e9 + 7;
47+
int l = 0;
48+
int r = nums.size() - 1;
49+
int res = 0;
50+
sort(nums.begin(), nums.end());
51+
while (l <= r) {
52+
if (nums[l] + nums[r] > target) {
53+
r -= 1;
54+
} else {
55+
res = (res + pow(2, r - l, mod)) % mod;
56+
l += 1;
57+
}
58+
}
59+
60+
return res;
61+
}
62+
63+
int pow(int x, int power, int mod) {
64+
int res = 1;
65+
while (power) {
66+
if (power % 2 == 1) {
67+
res = (1LL * res * x) % mod;
68+
}
69+
x = (1LL * x * x) % mod;
70+
power /= 2;
71+
}
72+
return res;
73+
}
74+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Tag: Array, Two Pointers, Binary Search, Sorting
2+
# Time: O(NLogN)
3+
# Space: O(1)
4+
# Ref: -
5+
# Note: -
6+
7+
# You are given an array of integers nums and an integer target.
8+
# Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 109 + 7.
9+
#  
10+
# Example 1:
11+
#
12+
# Input: nums = [3,5,6,7], target = 9
13+
# Output: 4
14+
# Explanation: There are 4 subsequences that satisfy the condition.
15+
# [3] -> Min value + max value <= target (3 + 3 <= 9)
16+
# [3,5] -> (3 + 5 <= 9)
17+
# [3,5,6] -> (3 + 6 <= 9)
18+
# [3,6] -> (3 + 6 <= 9)
19+
#
20+
# Example 2:
21+
#
22+
# Input: nums = [3,3,6,8], target = 10
23+
# Output: 6
24+
# Explanation: There are 6 subsequences that satisfy the condition. (nums can have repeated numbers).
25+
# [3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]
26+
#
27+
# Example 3:
28+
#
29+
# Input: nums = [2,3,3,4,6,7], target = 12
30+
# Output: 61
31+
# Explanation: There are 63 non-empty subsequences, two of them do not satisfy the condition ([6,7], [7]).
32+
# Number of valid subsequences (63 - 2 = 61).
33+
#
34+
#  
35+
# Constraints:
36+
#
37+
# 1 <= nums.length <= 105
38+
# 1 <= nums[i] <= 106
39+
# 1 <= target <= 106
40+
#
41+
#
42+
43+
class Solution:
44+
def numSubseq(self, nums: List[int], target: int) -> int:
45+
l = 0
46+
r = len(nums) - 1
47+
mod = 10 ** 9 + 7
48+
nums.sort()
49+
res = 0
50+
while l <= r:
51+
if nums[l] + nums[r] > target:
52+
r -= 1
53+
else:
54+
res = (res + pow(2, r - l, mod)) % mod
55+
l += 1
56+
57+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Tag: Array, Simulation
2+
// Time: O(N)
3+
// Space: O(1)
4+
// Ref: -
5+
// Note: -
6+
// Video: https://youtu.be/M2ccKRFVX8M
7+
8+
// Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.
9+
// A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).
10+
//  
11+
// Example 1:
12+
//
13+
// Input: nums = [0,2,1,5,3,4]
14+
// Output: [0,1,2,4,5,3]
15+
// Explanation: The array ans is built as follows:
16+
// ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
17+
// = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]
18+
// = [0,1,2,4,5,3]
19+
// Example 2:
20+
//
21+
// Input: nums = [5,0,1,2,3,4]
22+
// Output: [4,5,0,1,2,3]
23+
// Explanation: The array ans is built as follows:
24+
// ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
25+
// = [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]
26+
// = [4,5,0,1,2,3]
27+
//  
28+
// Constraints:
29+
//
30+
// 1 <= nums.length <= 1000
31+
// 0 <= nums[i] < nums.length
32+
// The elements in nums are distinct.
33+
//
34+
//  
35+
// Follow-up: Can you solve it without using an extra space (i.e., O(1) memory)?
36+
//
37+
38+
class Solution {
39+
public:
40+
vector<int> buildArray(vector<int>& nums) {
41+
int n = nums.size();
42+
vector<int> res(n, 0);
43+
for (int i = 0; i < n; i++) {
44+
res[i] = nums[nums[i]];
45+
}
46+
return res;
47+
}
48+
};
49+
50+
class Solution {
51+
public:
52+
vector<int> buildArray(vector<int>& nums) {
53+
int n = nums.size();
54+
for (int i = 0; i < n; i++) {
55+
int low = nums[i];
56+
int high = nums[nums[i]] % n;
57+
nums[i] = high * n + low;
58+
}
59+
60+
for (int i = 0; i < n; i++) {
61+
nums[i] /= n;
62+
}
63+
return nums;
64+
}
65+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Tag: Array, Simulation
2+
# Time: O(N)
3+
# Space: O(1)
4+
# Ref: -
5+
# Note: -
6+
# Video: https://youtu.be/M2ccKRFVX8M
7+
8+
# Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.
9+
# A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).
10+
#  
11+
# Example 1:
12+
#
13+
# Input: nums = [0,2,1,5,3,4]
14+
# Output: [0,1,2,4,5,3]
15+
# Explanation: The array ans is built as follows:
16+
# ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
17+
# = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]
18+
# = [0,1,2,4,5,3]
19+
# Example 2:
20+
#
21+
# Input: nums = [5,0,1,2,3,4]
22+
# Output: [4,5,0,1,2,3]
23+
# Explanation: The array ans is built as follows:
24+
# ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
25+
# = [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]
26+
# = [4,5,0,1,2,3]
27+
#  
28+
# Constraints:
29+
#
30+
# 1 <= nums.length <= 1000
31+
# 0 <= nums[i] < nums.length
32+
# The elements in nums are distinct.
33+
#
34+
#  
35+
# Follow-up: Can you solve it without using an extra space (i.e., O(1) memory)?
36+
#
37+
38+
class Solution:
39+
def buildArray(self, nums: List[int]) -> List[int]:
40+
n = len(nums)
41+
res = [0 for i in range(n)]
42+
for i in range(n):
43+
res[i] = nums[nums[i]]
44+
return res
45+
46+
class Solution:
47+
def buildArray(self, nums: List[int]) -> List[int]:
48+
n = len(nums)
49+
for i in range(n):
50+
old = nums[i]
51+
new = nums[nums[i]] % n
52+
nums[i] = new * n + old
53+
54+
for i in range(n):
55+
nums[i] //= n
56+
return nums

list/endlesscheng.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
114. https://leetcode.com/problems/container-with-most-water/ +Mark
134134
115. https://leetcode.com/problems/trapping-rain-water/ +Mark
135135
116. https://leetcode.com/problems/split-two-strings-to-make-palindrome/ +Mark
136-
- https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/
136+
117. https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/ +Mark
137137
- https://leetcode.com/problems/count-pairs-of-nodes/
138138
- https://leetcode.com/problems/two-sum-less-than-k/
139139
- https://leetcode.com/problems/sort-transformed-array/

0 commit comments

Comments
 (0)