mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge branch 'youngyangyang04:master' into master
This commit is contained in:
@ -247,6 +247,24 @@ class Solution:
|
||||
|
||||
### Go:
|
||||
|
||||
```go
|
||||
// 暴力法
|
||||
// 时间复杂度 O(n^2)
|
||||
// 空间复杂度 O(1)
|
||||
func removeElement(nums []int, val int) int {
|
||||
size := len(nums)
|
||||
for i := 0; i < size; i ++ {
|
||||
if nums[i] == val {
|
||||
for j := i + 1; j < size; j ++ {
|
||||
nums[j - 1] = nums[j]
|
||||
}
|
||||
i --
|
||||
size --
|
||||
}
|
||||
}
|
||||
return size
|
||||
}
|
||||
```
|
||||
```go
|
||||
// 快慢指针法
|
||||
// 时间复杂度 O(n)
|
||||
@ -289,7 +307,6 @@ func removeElement(nums []int, val int) int {
|
||||
right--
|
||||
}
|
||||
}
|
||||
fmt.Println(nums)
|
||||
return left
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user