[LeetCode]27. Remove Element
发布时间:2020-12-20 11:02:14 所属栏目:Python 来源:网络整理
导读:Success Details? Runtime:? 52 ms,faster than? 8.08%?of?Python3?online submissions for?Remove Element. Memory Usage:? 13.8 MB,less than? 6.06%?of?Python3?online submissions for?Remove Element. ? Submission Detail 113 / 113?test cases passed
Success
Details?
Runtime:?
52 ms,faster than?8.08%?of?Python3?online submissions for?Remove Element.
Memory Usage:?
13.8 MB,less than?6.06%?of?Python3?online submissions for?Remove Element.
?
Submission Detail
class Solution: def removeElement(self,nums: List[int],val: int) -> int: #0 if val ==None or nums == None: return None if len(nums) == 0: return 0 #normal count = nums.count(val) for i in range(count): nums.remove(val) return len(nums) ? 本来以为这样写简洁一点,结果比直接用remove还慢。。 ? 24ms: class Solution: def removeElement(self,val: int) -> int: while val in nums: for num in nums: if num == val: nums.remove(num) return len(nums) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Python位掩码(可变长度)
- python – mysql.connector – SQL语法中有错误;第1行’%s
- python:用户站点中的包不覆盖ubuntu上的dist-packages
- python – Google Colab-ValueError:Mountpoint必须位于存
- 如何从自制程序,分发,macports,pip卸载所有软件包?
- python – sys.path.append(‘…’)语句应该去哪里?
- Python对两个有序列表进行合并和排序的例子
- 【python-leetcode287-循环排序】寻找重复的数
- 在Django的视图中使用数据库查询的方法
- python 2支持vim
推荐文章
站长推荐
热点阅读