0027. 移除元素 #242
0027. 移除元素
#242
Replies: 1 comment 1 reply
-
class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
slow,fast=0,0
while fast < len(nums):
if nums[fast] != val:
# 这里直接赋值就可以了
nums[slow] = nums[fast]
slow += 1
fast += 1
return slow |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
0027. 移除元素
--- 0027. 移除元素 标签:数组、双指针 难度:简单 题目链接 0027. 移除元素 - 力扣 题目大意 描述:给定一个数组 nums,和一个值 val。 要求:不使用额外数组空间,将数组中所有数值等于 val 值的元素移除掉,并且返回新数组的长度。 说明: 0≤nums.length≤100。 0≤nums[i]≤50。 0≤val≤100。...
https://algo.itcharge.cn/solutions/0001-0099/remove-element/
Beta Was this translation helpful? Give feedback.
All reactions