Skip to content

Commit

Permalink
Time: 0 ms (100%), Space: 4.1 MB (68.95%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Mar 1, 2025
1 parent 7168408 commit f3e4cef
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions 0027-remove-element/0027-remove-element.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
func removeElement(nums []int, val int) int {
ans := 0
for i := 0; i < len(nums); i++ {
if nums[i] != val {
nums[ans] = nums[i]
ans += 1
res := 0
l, r := 0, 0
for r < len(nums) {
if nums[r] != val {
nums[l] = nums[r]
l += 1
res += 1
}

r += 1
}

return ans
return res
}

0 comments on commit f3e4cef

Please sign in to comment.