package main
func main() {
// nums := []int{3, 2, 2, 3}
// val := 3
nums := []int{0, 1, 2, 2, 3, 0, 4, 2}
val := 2
removeElement(nums, val)
}
func removeElement(nums []int, val int) int {
i := 0
n := len(nums)
for i < n {
if nums[i] == val {
n--
nums[i] = nums[n]
} else {
i++
}
}
return n
}
'Algorithm > Go' 카테고리의 다른 글
[LeetCode] climbing Stairs (2) | 2022.02.07 |
---|---|
[LeetCode] Best Time to Buy and Sell Stock (0) | 2022.01.24 |
[LeetCode] Adding Spaces to a String (0) | 2022.01.24 |
[LeetCode] Maximum Subarray (0) | 2022.01.10 |
[LeetCode] Longest Common Prefix (0) | 2022.01.09 |