题目: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.

代码:

 class Solution
{
public:
int removeElement(int A[], int n, int elem)
{
for (int i = ; i < n; ++i)
{
if (A[i] == elem)
{
for (int j = i; j < n; ++j)
{
A[j] = A[j+];
}
n--;
i--;
}
}
return n;
}
};

【LeetCode OJ】Remove Element的更多相关文章

  1. 【LeetCode OJ】Remove Duplicates from Sorted Array

    题目:Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  2. 【LeetCode OJ】Remove Nth Node From End of List

    题目:Given a linked list, remove the nth node from the end of list and return its head. For example: G ...

  3. 【LeetCode OJ】Majority Element

    题目:Given an array of size n, find the majority element. The majority element is the element that app ...

  4. 【LeetCode 229】Majority Element II

    Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...

  5. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  6. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  7. 【LeetCode OJ】Pascal's Triangle II

    Problem Link: http://oj.leetcode.com/problems/pascals-triangle-ii/ Let T[i][j] be the j-th element o ...

  8. 【LeetCode OJ】Triangle

    Problem Link: http://oj.leetcode.com/problems/triangle/ Let R[][] be a 2D array where R[i][j] (j < ...

  9. 【LeetCode OJ】Longest Consecutive Sequence

    Problem Link: http://oj.leetcode.com/problems/longest-consecutive-sequence/ This problem is a classi ...

随机推荐

  1. 使用xshell5 从CentOS主机download资料

    需要安装一个软件,步骤如下: 第一步,找出软件的完整名称: 第二步,安装该软件: 第三步,执行sz命令. 参考下面的执行过程 [root@mylinux ~]# yum provides lrzsz* ...

  2. js json日期格式转换日期方法

      接收json数据,日期格式为:"\/Date(1414078309687)\/" var value = "/Date(1414078309687)/"; ...

  3. ViewBag和ViewDate以及TempDate的区别

    简单的说,就是   ViewBag 和  ViewData 是数据共享的(他们都是共享 ViewData 的数据),ViewBag 实际就是对 ViewData的一个操作的封装.  区别 : View ...

  4. Win10无法使用内置管理员用户打开edge解决方案

    https://jingyan.baidu.com/article/4f7d5712d23f1b1a2119274b.html

  5. 小程序的tab切换事件

    index.wxml代码 <view class="tab-left" > <view " bindtap="tab">tab ...

  6. Http Cookie Manager、session

     1. JMeter Http Cookie Manager的作用: (1)自动管理 (2)象浏览器一样的存储和发送Cookie.如果你请求一个站点,然后他的Response中包含Cookie,Coo ...

  7. vue-router2路由参数注意问题

    1.vue 路由 如果传递 params 定义路由的时候是 /路由名称:id 获取的时候 this.$route.params.id 最后形如 /路由名称/路由参数 传参的时候 params:{ st ...

  8. Dos命令大全(1)

    MS DOS 命令大全 一.基础命令 1 dir 无参数:查看当前所在目录的文件和文件夹. /s:查看当前目录已经其所有子目录的文件和文件夹. /a:查看包括隐含文件的所有文件. /ah:只显示出隐含 ...

  9. jar包的启动和停止脚本

    启动: #!/bin/sh PIDFILE="/app/eureka/eureka.pid" LOGFILE="/app/eureka/out.log" if ...

  10. Java终止循环体

    编写程序,是先创建一个字符串数组,在使用foreach语句遍历时,如果发现数组中包含字符串“老鹰”则立刻中断循环.再创建一个整数类型的二维数组,使用双层foreach语句循环遍历,当发现第一个小于60 ...