8000 Update: remove_element.go by awesee · Pull Request #3 · hitzzc/go-leetcode · GitHub
[go: up one dir, main page]

Skip to content

Update: remove_element.go #3

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update remove_element.go
  • Loading branch information
Sandy authored Dec 10, 2018
commit 8547e55f43fbdc77fb327ebac51ad612f99bee13
18 changes: 9 additions & 9 deletions remove_element/remove_element.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package remove_element

func removeElement(nums []int, val int) int {
start := 0
for i := 0; i < len(nums); i++ {
if nums[i] == val {
continue
}
nums[start] = nums[i]
start++
}
return start
l := 0
for _, v := range nums {
if v != val {
nums[l] = v
l++
}
}

return l
}
0