您的位置:首页 > 编程语言 > Python开发

leetcode.array--27. Remove Element

2017-10-03 14:47 375 查看
问题:27. Remove Element

问题描述:https://leetcode.com/problems/remove-element/description/

从序列中移除指定元素,返回新序列的长度。

Python:

class Solution(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)

好像要比O(n)遍历还要快一点,应该是Python做过优化??
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python leetcode