File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed
docs/data-structure/array Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -274,8 +274,10 @@ class Solution:
274274 - 同步增长双指针
275275- 若 ` nums[j] == val `
276276 - j 变为快指针:` j = j + 1 `
277-
278- ### Python
277+
278+ <!-- tabs: start -->
279+
280+ #### ** Python**
279281
280282``` python
281283# python3
@@ -301,6 +303,36 @@ class Solution:
301303 return res
302304```
303305
306+ #### ** Go**
307+
308+ ``` go
309+ func removeElement (nums []int , val int ) int {
310+ length := len (nums)
311+ if length == 0 {
312+ return 0
313+ }
314+
315+ i := 0
316+ j := 0
317+ for j < length {
318+ if nums[j] == val {
319+ // 去找一个不是 val 的值
320+ j++
321+ } else {
322+ // 互换
323+ nums[i], nums[j] = nums[j], nums[i]
324+ // i 在前进的过程中走的是 j 走过的路,一定不会再碰到 val
325+ i++
326+ j++
327+ }
328+ }
329+
330+ return length - (j - i)
331+ }
332+ ```
333+
334+ <!-- tabs: end -->
335+
304336
305337## 33. 搜索旋转排序数组
306338
You can’t perform that action at this time.
0 commit comments