Skip to content

Commit

Permalink
Merge pull request neetcode-gh#851 from MaratKhakim/27-Remove-Element-GO
Browse files Browse the repository at this point in the history
GO: 27. Remove Element
  • Loading branch information
Ahmad-A0 authored Aug 19, 2022
2 parents 191c61c + 3728e04 commit 7f6dcbc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions go/27-Remove-Element.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
func removeElement(nums []int, val int) int {
left, right := 0, len(nums)-1

for left <= right {
if nums[left] == val {
nums[left], nums[right] = nums[right], nums[left]
right--
} else {
left++
}
}

return left
}

0 comments on commit 7f6dcbc

Please sign in to comment.