We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 769ecf7 commit 4ae39dcCopy full SHA for 4ae39dc
Two Pointers/80. 删除有序数组中的重复项 II.md
@@ -51,13 +51,12 @@ for (int i = 0; i < len; i++) {
51
52
---
53
54
-快慢指针(或者滑动窗口):
+快慢指针:
55
56
慢指针记录被替换的下标,快指针记录待检查的下标。
57
58
-或者是长度为 3 的滑动窗口,该窗口中不能包含相等的元素。
59
-
60
```Java
+//Java
61
class Solution {
62
public int removeDuplicates(int[] nums) {
63
int n = nums.length;
@@ -73,4 +72,24 @@ class Solution {
73
72
return slow;
74
}
75
+```
76
+
77
78
+```go
79
+//Go
80
+func removeDuplicates(nums []int) int {
81
+ n := len(nums)
82
+ if n <= 2 {
83
+ return n
84
+ }
85
+ slow, fast := 2, 2
86
+ for ;fast < n; {
87
+ if nums[slow - 2] != nums[fast] {
88
+ nums[slow] = nums[fast]
89
+ slow++
90
91
+ fast++
92
93
+ return slow
94
+}
95
```
0 commit comments