---
description: '#双指针'
---

# 移除元素

[27 移除元素](https://leetcode.cn/problems/remove-element/description/)



```golang
func removeElement(nums []int, val int) int {

    l,r:=0,0

    for r<len(nums){
        if nums[r]!=val{
            nums[l]=nums[r]
            l++
        }
        r++
    }
    return l

}
```
