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

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

ps:这个题目同样是一个双指针的问题,比较简单,代码如下所示

 class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int pos = ;
int sz = nums.size();
for (int i = ; i < sz; ++i){
if (nums[i] != val){
nums[pos++] = nums[i];
}
}
return pos;
}
};

java版本:

 public class Solution {
public int removeElement(int[] nums, int val) {
int pos = 0;
for(int i = 0; i < nums.length; ++i){
if(nums[i] != val)
nums[pos++] = nums[i];
}
return pos;
}
}

最新文章

  1. Xcode8 pod install 报错 “Generating Pods project Abort trap
  2. mac上如何卸载oracle jdk 1.7
  3. MFC CheckBox
  4. HealthKit开发快速入门教程之HealthKit数据的操作
  5. (转)Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
  6. 如何查看你的 memcached 的状态
  7. 《HTML5 从入门到精通--7.6.3 单元格垂直跨度——rowspan》
  8. 微软源代码管理工具TFS2013安装与使用图文教程
  9. CentOS 安装以及配置Apache php mysql
  10. asp中的动态数组
  11. Java 多线程总结
  12. 微信开发基于springboot
  13. windows服务器环境问题---api-ms-win-crt-runtimel1-1-0.dll缺失解决
  14. sql生成连续日期(年份、月份、日期)
  15. CUDA[3] Samples for accessing shared/global memory
  16. 【BI】OLTP与OLAP的区别
  17. 基于qml创建最简单的图像处理程序(3)-使用opencv&amp;qml进行图像处理
  18. VS2017 加载项目 :未找到框架“.NETFramework,Version=v4.7”的引用程序集(出坑指南)
  19. CANOpen学习指南
  20. linux tail -f 和 tail -F的区别 &amp;&amp; tail 的断点续传

热门文章

  1. 用仿ActionScript的语法来编写html5——第五篇,Graphics绘图
  2. [转]Asp.net MVC 中Ajax的使用
  3. netty5----心跳
  4. Thrift简单调用
  5. C# ---sender
  6. Tomcat:解决Tomcat可以在eclipse启动,却无法显示默认页面的操作
  7. ubuntu 致命错误: zlib.h:没有那个文件或目录【转】
  8. 【P3355】骑士共存问题(最大流+黑白染色,洛谷)
  9. css常用知识点——思维导图
  10. spring boot项目获取application配置文件参数的两种方式