您的位置:首页 > 其它

LeetCode(27) Remove Element

2017-12-21 15:10 387 查看
这道题跟26题的测评方法类似,思路也很简单,就是遍历数组,把与val不相同的数调到前面就行。

下附AC代码:

class Solution:
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
lens = 0
for i in range(len(nums)):
if val != nums[i]:
nums[lens]=nums[i]
lens+=1
return lens
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: