Skip to content

Commit 6ec759e

Browse files
add Solution 0026 [golang]
1 parent 31c410b commit 6ec759e

File tree

1 file changed

+21
-0
lines changed
  • solution/0026.Remove Duplicates from Sorted Array

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @lc app=leetcode.cn id=26 lang=golang
3+
* Accepted
4+
* 161/161 cases passed (144 ms)
5+
* Your runtime beats 36.91 % of golang submissions
6+
* Your memory usage beats 40.4 % of golang submissions (8.2 MB)
7+
*/
8+
9+
func removeDuplicates(nums []int) int {
10+
if nums == nil || len(nums) == 0 {
11+
return 0
12+
}
13+
j := 0
14+
for i := 1; i < len(nums); i++ {
15+
if nums[j] != nums[i] {
16+
j++
17+
nums[j] = nums[i]
18+
}
19+
}
20+
return j + 1
21+
}

0 commit comments

Comments
 (0)