mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0027.移除元素.md
This commit is contained in:
@ -199,7 +199,23 @@ def remove_element(nums, val)
|
|||||||
i
|
i
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
Rust:
|
||||||
|
```rust
|
||||||
|
pub fn remove_element(nums: &mut Vec<i32>, val: i32) -> &mut Vec<i32> {
|
||||||
|
let mut start: usize = 0;
|
||||||
|
while start < nums.len() {
|
||||||
|
if nums[start] == val {
|
||||||
|
nums.remove(start);
|
||||||
|
}
|
||||||
|
start += 1;
|
||||||
|
}
|
||||||
|
nums
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
let mut nums = vec![5,1,3,5,2,3,4,1];
|
||||||
|
println!("{:?}",remove_element(&mut nums, 5));
|
||||||
|
}
|
||||||
|
```
|
||||||
-----------------------
|
-----------------------
|
||||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||||
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
||||||
|
Reference in New Issue
Block a user