go: add «26. Remove Duplicates from Sorted Array»
URL: https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
3a4809d6f8
commit
3a68075b5a
1 changed files with 14 additions and 0 deletions
14
go/remove-duplicates-from-sorted-array.go
Normal file
14
go/remove-duplicates-from-sorted-array.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
func removeDuplicates(nums []int) int {
|
||||
l := 1
|
||||
|
||||
for r := 1; r < len(nums); r++ {
|
||||
if nums[r-1] != nums[r] {
|
||||
nums[l] = nums[r]
|
||||
l++
|
||||
}
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue