class Solution_1(object):
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
while val in nums:
nums.remove(val)
return len(nums)
class Solution_2(object):
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
j = 0
for i in range(len(nums)):
if nums[i] != val:
nums[j] = nums[i]
j += 1
return j
【LeetCode】27. Remove Element
猜你喜欢
转载自blog.csdn.net/zzc15806/article/details/81190971
今日推荐
周排行