Skip to content

Commit e24713f

Browse files
committed
May-22
1 parent 8690bbd commit e24713f

16 files changed

+684
-97
lines changed

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
4242
| [52%] | [leetcode-discuss.md](./list/leetcode-discuss.md) | 45/85 | 1 vip |
4343
| [53%] | [leetcode-75.md](./list/leetcode-75.md) | 40/75 | - |
4444
| [55%] | [leetcode-topics.md](./list/leetcode-topics.md) | 80/144 | - |
45-
| [86%] | [leetcode-top-interview-150.md](./list/leetcode-top-interview-150.md) | 130/150 | - |
45+
| [87%] | [leetcode-top-interview-150.md](./list/leetcode-top-interview-150.md) | 131/150 | - |
4646
| [95%] | [neetcode150.md](./list/neetcode150.md) | 143/150 | - |
4747
| [] | [9c-advanced.md](./list/9c-advanced.md) | 75/93 | 18 vips |
4848
| [] | [9c-dp.md](./list/9c-dp.md) | 42/45 | 3 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) | 122/2210 | 6 vips |
58+
| [🔲] | [endlesscheng.md](./list/endlesscheng.md) | 128/2210 | 6 vips |
5959

60-
**Solved**: 716 problems
60+
**Solved**: 719 problems
6161

6262
## 类型/Category
6363

@@ -897,7 +897,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
897897

898898
## Two Pointers
899899

900-
| Link | Problem(69) | Solution | Tag | Time | Space | Ref |
900+
| Link | Problem(75) | Solution | Tag | Time | Space | Ref |
901901
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
902902
| [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\) | - |
903903
| [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\) | - |
@@ -931,6 +931,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
931931
| [Leetcode-2570](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values/) | Merge Two 2D Arrays By Summing Values | [c++](./leetcode/2570.merge-two-2d-arrays-by-summing-values.cpp), [python3](./leetcode/2570.merge-two-2d-arrays-by-summing-values.py) | Two Pointers | O\(N\) | O\(1\) | - |
932932
| [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\) | - |
933933
| [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\) | - |
934+
| [Leetcode-283](https://leetcode.com/problems/move-zeroes/) | Move Zeroes | [c++](./leetcode/283.move-zeroes.cpp), [python3](./leetcode/283.move-zeroes.py) | Two Pointers | O\(N\) | O\(1\) | - |
934935
| [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\) | - |
935936
| [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\) | - |
936937
| [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\) | - |
@@ -940,11 +941,16 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
940941
| [Leetcode-763](https://leetcode.com/problems/partition-labels/) | Partition Labels | [c++](./leetcode/763.partition-labels.cpp), [python3](./leetcode/763.partition-labels.py) | Two Pointers | O\(N\) | O\(N\) | - |
941942
| [Leetcode-838](https://leetcode.com/problems/push-dominoes/) | Push Dominoes | [c++](./leetcode/838.push-dominoes.cpp), [python3](./leetcode/838.push-dominoes.py) | Two Pointers | O\(N\) | O\(N\) | - |
942943
| [Leetcode-2122](https://leetcode.com/problems/recover-the-original-array/) | Recover The Original Array | [c++](./leetcode/2122.recover-the-original-array.cpp), [python3](./leetcode/2122.recover-the-original-array.py) | Two Pointers | O\(N^2\) | O\(1\) | - |
944+
| [Leetcode-26](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | Remove Duplicates From Sorted Array | [c++](./leetcode/26.remove-duplicates-from-sorted-array.cpp), [python3](./leetcode/26.remove-duplicates-from-sorted-array.py) | Two Pointers | O\(N\) | O\(1\) | - |
945+
| [Leetcode-80](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/) | Remove Duplicates From Sorted Array II | [c++](./leetcode/80.remove-duplicates-from-sorted-array-ii.cpp), [python3](./leetcode/80.remove-duplicates-from-sorted-array-ii.py) | Two Pointers | O\(N\) | O\(1\) | - |
946+
| [Leetcode-27](https://leetcode.com/problems/remove-element/) | Remove Element | [c++](./leetcode/27.remove-element.cpp), [python3](./leetcode/27.remove-element.py) | Two Pointers | O\(N\) | O\(1\) | - |
943947
| [Leetcode-19](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) | Remove Nth Node From End Of List | [c++](./leetcode/19.remove-nth-node-from-end-of-list.cpp), [python3](./leetcode/19.remove-nth-node-from-end-of-list.py) | Two Pointers | O\(N\) | O\(1\) | - |
944948
| [Leetcode-344](https://leetcode.com/problems/reverse-string/) | Reverse String | [c++](./leetcode/344.reverse-string.cpp), [python3](./leetcode/344.reverse-string.py) | Two Pointers | O\(N\) | O\(1\) | - |
945949
| [Leetcode-189](https://leetcode.com/problems/rotate-array/) | Rotate Array | [c++](./leetcode/189.rotate-array.cpp), [python3](./leetcode/189.rotate-array.py) | Two Pointers | O\(N\) | O\(1\) | - |
946950
| [Leetcode-1574](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted/) | Shortest Subarray To Be Removed To Make Array Sorted | [c++](./leetcode/1574.shortest-subarray-to-be-removed-to-make-array-sorted.cpp), [python3](./leetcode/1574.shortest-subarray-to-be-removed-to-make-array-sorted.py) | Two Pointers | O\(N\) | O\(1\) | - |
947951
| [Leetcode-581](https://leetcode.com/problems/shortest-unsorted-continuous-subarray/) | Shortest Unsorted Continuous Subarray | [c++](./leetcode/581.shortest-unsorted-continuous-subarray.cpp), [python3](./leetcode/581.shortest-unsorted-continuous-subarray.py) | Two Pointers | O\(N\) | O\(1\) | - |
952+
| [Leetcode-905](https://leetcode.com/problems/sort-array-by-parity/) | Sort Array By Parity | [c++](./leetcode/905.sort-array-by-parity.cpp), [python3](./leetcode/905.sort-array-by-parity.py) | Two Pointers | O\(N\) | O\(1\) | - |
953+
| [Leetcode-922](https://leetcode.com/problems/sort-array-by-parity-ii/) | Sort Array By Parity II | [c++](./leetcode/922.sort-array-by-parity-ii.cpp), [python3](./leetcode/922.sort-array-by-parity-ii.py) | Two Pointers | O\(N\) | O\(1\) | - |
948954
| [Leetcode-75](https://leetcode.com/problems/sort-colors/) | Sort Colors | [c++](./leetcode/75.sort-colors.cpp), [python3](./leetcode/75.sort-colors.py) | Two Pointers | O\(N\) | O\(1\) | - |
949955
| [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\) | - |
950956
| [Leetcode-1616](https://leetcode.com/problems/split-two-strings-to-make-palindrome/) | Split Two Strings To Make Palindrome | [c++](./leetcode/1616.split-two-strings-to-make-palindrome.cpp), [python3](./leetcode/1616.split-two-strings-to-make-palindrome.py) | Two Pointers | O\(N\) | O\(1\) | - |
@@ -1065,7 +1071,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
10651071

10661072
## Sorting
10671073

1068-
| Link | Problem(87) | Solution | Tag | Time | Space | Ref |
1074+
| Link | Problem(89) | Solution | Tag | Time | Space | Ref |
10691075
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
10701076
| [Leetcode-15](https://leetcode.com/problems/3sum/) | 3Sum | [c++](./leetcode/15.3sum.cpp), [python3](./leetcode/15.3sum.py) | Sorting | O\(N^2\) | O\(1\) | - |
10711077
| [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\) | - |
@@ -1140,6 +1146,8 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
11401146
| [Leetcode-354](https://leetcode.com/problems/russian-doll-envelopes/) | Russian Doll Envelopes | [c++](./leetcode/354.russian-doll-envelopes.cpp), [python3](./leetcode/354.russian-doll-envelopes.py) | Sorting | O\(NlogN\) | O\(N\) | - |
11411147
| [Leetcode-581](https://leetcode.com/problems/shortest-unsorted-continuous-subarray/) | Shortest Unsorted Continuous Subarray | [c++](./leetcode/581.shortest-unsorted-continuous-subarray.cpp), [python3](./leetcode/581.shortest-unsorted-continuous-subarray.py) | Sorting | O\(N\) | O\(1\) | - |
11421148
| [Leetcode-632](https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists/) | Smallest Range Covering Elements From K Lists | [c++](./leetcode/632.smallest-range-covering-elements-from-k-lists.cpp), [python3](./leetcode/632.smallest-range-covering-elements-from-k-lists.py) | Sorting | O\(NlogN\) | O\(N\) | - |
1149+
| [Leetcode-905](https://leetcode.com/problems/sort-array-by-parity/) | Sort Array By Parity | [c++](./leetcode/905.sort-array-by-parity.cpp), [python3](./leetcode/905.sort-array-by-parity.py) | Sorting | O\(N\) | O\(1\) | - |
1150+
| [Leetcode-922](https://leetcode.com/problems/sort-array-by-parity-ii/) | Sort Array By Parity II | [c++](./leetcode/922.sort-array-by-parity-ii.cpp), [python3](./leetcode/922.sort-array-by-parity-ii.py) | Sorting | O\(N\) | O\(1\) | - |
11431151
| [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\) | - |
11441152
| [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\) | - |
11451153
| [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\) | - |
@@ -1567,7 +1575,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
15671575

15681576
## Other
15691577

1570-
| Link | Problem(100) | Solution | Tag | Time | Space | Ref |
1578+
| Link | Problem(97) | Solution | Tag | Time | Space | Ref |
15711579
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
15721580
| [Leetcode-454](https://leetcode.com/problems/4sum-ii/) | 4Sum II | [c++](./leetcode/454.4sum-ii.cpp) | Other | \- | \- | - |
15731581
| [Leetcode-269](https://leetcode.com/problems/alien-dictionary/) | Alien Dictionary | [python3](./leetcode/269.alien-dictionary.py) | Other | \- | \- | - |
@@ -1619,7 +1627,6 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
16191627
| [Leetcode-928](https://leetcode.com/problems/minimize-malware-spread-ii/) | Minimize Malware Spread II | [python3](./leetcode/928.minimize-malware-spread-ii.py) | Other | \- | \- | - |
16201628
| [Leetcode-433](https://leetcode.com/problems/minimum-genetic-mutation/) | Minimum Genetic Mutation | [c++](./leetcode/433.minimum-genetic-mutation.cpp), [python3](./leetcode/433.minimum-genetic-mutation.py) | Other | \- | \- | - |
16211629
| [Leetcode-599](https://leetcode.com/problems/minimum-index-sum-of-two-lists/) | Minimum Index Sum Of Two Lists | [c++](./leetcode/599.minimum-index-sum-of-two-lists.cpp) | Other | \- | \- | - |
1622-
| [Leetcode-283](https://leetcode.com/problems/move-zeroes/) | Move Zeroes | [c++](./leetcode/283.move-zeroes.cpp), [python3](./leetcode/283.move-zeroes.py) | Other | \- | \- | - |
16231630
| [Leetcode-346](https://leetcode.com/problems/moving-average-from-data-stream/) | Moving Average From Data Stream | [c++](./leetcode/346.moving-average-from-data-stream.cpp), [python3](./leetcode/346.moving-average-from-data-stream.py) | Other | \- | \- | - |
16241631
| [Leetcode-31](https://leetcode.com/problems/next-permutation/) | Next Permutation | [c++](./leetcode/31.next-permutation.cpp), [python3](./leetcode/31.next-permutation.py) | Other | \- | \- | - |
16251632
| [Leetcode-447](https://leetcode.com/problems/number-of-boomerangs/) | Number Of Boomerangs | [c++](./leetcode/447.number-of-boomerangs.cpp), [python3](./leetcode/447.number-of-boomerangs.py) | Other | \- | \- | - |
@@ -1634,8 +1641,6 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
16341641
| [Leetcode-119](https://leetcode.com/problems/pascals-triangle-ii/) | Pascals Triangle II | [c++](./leetcode/119.pascals-triangle-ii.cpp), [python3](./leetcode/119.pascals-triangle-ii.py) | Other | \- | \- | - |
16351642
| [Leetcode-66](https://leetcode.com/problems/plus-one/) | Plus One | [c++](./leetcode/66.plus-one.cpp), [python3](./leetcode/66.plus-one.py) | Other | \- | \- | - |
16361643
| [Leetcode-755](https://leetcode.com/problems/pour-water/) | Pour Water | [python3](./leetcode/755.pour-water.py) | Other | \- | \- | - |
1637-
| [Leetcode-26](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | Remove Duplicates From Sorted Array | [c++](./leetcode/26.remove-duplicates-from-sorted-array.cpp), [python3](./leetcode/26.remove-duplicates-from-sorted-array.py) | Other | \- | \- | - |
1638-
| [Leetcode-27](https://leetcode.com/problems/remove-element/) | Remove Element | [c++](./leetcode/27.remove-element.cpp), [python3](./leetcode/27.remove-element.py) | Other | \- | \- | - |
16391644
| [Leetcode-203](https://leetcode.com/problems/remove-linked-list-elements/) | Remove Linked List Elements | [python3](./leetcode/203.remove-linked-list-elements.py) | Other | \- | \- | - |
16401645
| [Leetcode-143](https://leetcode.com/problems/reorder-list/) | Reorder List | [python3](./leetcode/143.reorder-list.py) | Other | \- | \- | - |
16411646
| [Leetcode-7](https://leetcode.com/problems/reverse-integer/) | Reverse Integer | [c++](./leetcode/7.reverse-integer.cpp), [python3](./leetcode/7.reverse-integer.py) | Other | \- | \- | - |
Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,65 @@
1+
// Tag: Array, Two Pointers
2+
// Time: O(N)
3+
// Space: O(1)
4+
// Ref: -
5+
// Note: -
6+
7+
// Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.
8+
// Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:
9+
//
10+
// Change the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initially. The remaining elements of nums are not important as well as the size of nums.
11+
// Return k.
12+
//
13+
// Custom Judge:
14+
// The judge will test your solution with the following code:
15+
//
16+
// int[] nums = [...]; // Input array
17+
// int[] expectedNums = [...]; // The expected answer with correct length
18+
//
19+
// int k = removeDuplicates(nums); // Calls your implementation
20+
//
21+
// assert k == expectedNums.length;
22+
// for (int i = 0; i < k; i++) {
23+
// assert nums[i] == expectedNums[i];
24+
// }
25+
//
26+
// If all assertions pass, then your solution will be accepted.
27+
//  
28+
// Example 1:
29+
//
30+
// Input: nums = [1,1,2]
31+
// Output: 2, nums = [1,2,_]
32+
// Explanation: Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.
33+
// It does not matter what you leave beyond the returned k (hence they are underscores).
34+
//
35+
// Example 2:
36+
//
37+
// Input: nums = [0,0,1,1,1,2,2,3,3,4]
38+
// Output: 5, nums = [0,1,2,3,4,_,_,_,_,_]
39+
// Explanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.
40+
// It does not matter what you leave beyond the returned k (hence they are underscores).
41+
//
42+
//  
43+
// Constraints:
44+
//
45+
// 1 <= nums.length <= 3 * 104
46+
// -100 <= nums[i] <= 100
47+
// nums is sorted in non-decreasing order.
48+
//
49+
//
50+
151
class Solution {
252
public:
353
int removeDuplicates(vector<int>& nums) {
4-
5-
int i = 0;
6-
for (int j = 0; j < nums.size(); ++j)
7-
{
8-
if (i == 0 || nums[i - 1] < nums[j])
9-
{
10-
nums[i++] = nums[j];
54+
int n = nums.size();
55+
int l = 1;
56+
for (int i = 1; i < n; i++) {
57+
if (nums[i] == nums[l - 1]) {
58+
continue;
1159
}
60+
swap(nums[i], nums[l]);
61+
l += 1;
1262
}
13-
14-
return i;
63+
return l;
1564
}
16-
};
65+
};
Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,62 @@
1-
class Solution(object):
2-
def removeDuplicates(self, nums: List[int]) -> int:
3-
i = 0
4-
for j in range(len(nums)):
5-
if (i == 0 or nums[i - 1] < nums[j]):
6-
nums[i] = nums[j]
7-
i += 1
1+
# Tag: Array, Two Pointers
2+
# Time: O(N)
3+
# Space: O(1)
4+
# Ref: -
5+
# Note: -
86

9-
return i
7+
# Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.
8+
# Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:
9+
#
10+
# Change the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initially. The remaining elements of nums are not important as well as the size of nums.
11+
# Return k.
12+
#
13+
# Custom Judge:
14+
# The judge will test your solution with the following code:
15+
#
16+
# int[] nums = [...]; // Input array
17+
# int[] expectedNums = [...]; // The expected answer with correct length
18+
#
19+
# int k = removeDuplicates(nums); // Calls your implementation
20+
#
21+
# assert k == expectedNums.length;
22+
# for (int i = 0; i < k; i++) {
23+
# assert nums[i] == expectedNums[i];
24+
# }
25+
#
26+
# If all assertions pass, then your solution will be accepted.
27+
#  
28+
# Example 1:
29+
#
30+
# Input: nums = [1,1,2]
31+
# Output: 2, nums = [1,2,_]
32+
# Explanation: Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.
33+
# It does not matter what you leave beyond the returned k (hence they are underscores).
34+
#
35+
# Example 2:
36+
#
37+
# Input: nums = [0,0,1,1,1,2,2,3,3,4]
38+
# Output: 5, nums = [0,1,2,3,4,_,_,_,_,_]
39+
# Explanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.
40+
# It does not matter what you leave beyond the returned k (hence they are underscores).
41+
#
42+
#  
43+
# Constraints:
44+
#
45+
# 1 <= nums.length <= 3 * 104
46+
# -100 <= nums[i] <= 100
47+
# nums is sorted in non-decreasing order.
48+
#
49+
#
1050

11-
12-
class Solution2:
51+
class Solution:
1352
def removeDuplicates(self, nums: List[int]) -> int:
14-
15-
slow = fast = 0
16-
17-
while fast < len(nums):
18-
19-
while fast + 1 < len(nums) and nums[fast] == nums[fast + 1]:
20-
fast += 1
21-
22-
if nums[slow] < nums[fast]:
23-
nums[slow], nums[fast] = nums[fast], nums[slow]
24-
25-
slow += 1
26-
fast += 1
27-
28-
return slow
53+
n = len(nums)
54+
l = 1
55+
for i in range(1, n):
56+
if nums[i] == nums[l - 1]:
57+
continue
58+
59+
nums[i], nums[l] = nums[l], nums[i]
60+
l += 1
61+
62+
return l

0 commit comments

Comments
 (0)