题目描述:

中文:

给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度。

不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。

元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。

英文:

Given an array nums and a value val, remove all instances of that value in-place and return the new length.

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

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)

题目来源:力扣

最新文章

  1. 怎样实现ZBrush中的智能对称
  2. bzoj1029 [JSOI2007]建筑抢修
  3. 解决 Tomcat 无法绑定 80 端口的问题,以及 Tomcat 配置虚拟目录、二级域名等
  4. Owin中间件搭建OAuth2.0认证授权服务体会
  5. 批处理安装APK
  6. session共享,格式json,php不能简单的设置session.serialize_handler=json,目前只有php,wddx(xml),安装扩展后还有igbinary(二进制)
  7. Visual Studio 2010下载 + 附破解方法
  8. git使用的常见命令(一)
  9. Codevs 4768 跳石头 NOIP2015 DAY2 T1
  10. NetFlow
  11. OSX: 10.9的SMB网络共享连接可能破坏其权限设置
  12. 使用最小堆优化Dijkstra算法
  13. [SCOI2007]最大土地面积
  14. keepalived双机热备nginx
  15. <二>ELK-6.5.3学习笔记–使用rsyslog传输管理nginx日志
  16. windows server 2012 流媒体服务器搭建(直播与点播)
  17. [原]Jenkins(七)---jenkins项目编译测试发布由maven构建的web项目
  18. 雷林鹏分享:XML 编辑器
  19. 将远程mysql服务器数据导出 csv 并发送到我的本机
  20. 4. mysql 查看数据库中所有表的记录数

热门文章

  1. No enclosing instance of type TestGson is accessible. Must qualify the allocation with an enclosing instance of type TestGson (e.g. x.new A() where x is an instance of TestGson).
  2. java 时间戳转为时间
  3. 【HDU6701】Make Rounddog Happy【权值线段树+双向单调队列】
  4. (转)堆和栈的概念和区别 HeapOutOfMemory和StackOverflow解释
  5. JSP 获取访问者真正的IP地址
  6. JAVA 大数开方模板
  7. PHP连接FTP服务的简单实现
  8. codeforces 559D Randomizer
  9. Nuget-Swagger-Swashbuckle:Swashbuckle
  10. Linux随笔 - linux 多个会话同时执行命令后history记录不全的解决方案【转载】