mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
规范格式
This commit is contained in:
19
leetcode/0027.Remove-Element/27. Remove Element.go
Normal file
19
leetcode/0027.Remove-Element/27. Remove Element.go
Normal file
@ -0,0 +1,19 @@
|
||||
package leetcode
|
||||
|
||||
func removeElement(nums []int, val int) int {
|
||||
if len(nums) == 0 {
|
||||
return 0
|
||||
}
|
||||
j := 0
|
||||
for i := 0; i < len(nums); i++ {
|
||||
if nums[i] != val {
|
||||
if i != j {
|
||||
nums[i], nums[j] = nums[j], nums[i]
|
||||
j++
|
||||
} else {
|
||||
j++
|
||||
}
|
||||
}
|
||||
}
|
||||
return j
|
||||
}
|
Reference in New Issue
Block a user