题目: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. 飞机找不到,流量哪去了?记一次移动WAP网关导致的问题

    这几天随着客户端一个新版本发布,运维发现CDN的流量猛跌: 话说流量就是金钱,流量就是工资.领导很生气,后果很严重.没什么好说的,赶紧查!一开始怀疑服务端有问题,先受伤的总是我们,当然这也是没错的,因 ...

  2. Git -- 分支管理简介

    分支就是科幻电影里面的平行宇宙,当你正在电脑前努力学习Git的时候,另一个你正在另一个平行宇宙里努力学习SVN. 如果两个平行宇宙互不干扰,那对现在的你也没啥影响.不过,在某个时间点,两个平行宇宙合并 ...

  3. sqlite学习笔记1:编译数据库

    首先说下我使用的是Linux环境 一 下载源代码 官网下载:点这里 二 编译 1 解压 下载完毕之后通常会在当前用户的"下载"文件夹中,首先cd到下载文件夹,然后创建一个文件件.用 ...

  4. linux下怎么用tree命令以树形结构显示文件目录结构?

    tree命令以树状图列出文件目录结构.不过某些Linux上(Centos 6.4)没有tree命令,本文将介绍安装方法. 常用参数: ? 1 2 3 4 5 6 tree -d 只显示目录.   tr ...

  5. js判断字符串是否json格式

    function isJSON(str) { if (typeof str == 'string') { try { var obj=JSON.parse(str); if(typeof obj == ...

  6. 在Android平台下搭建PhoneGap开发环境--用HTML5开发游戏

    一.在Android平台下搭建PhoneGap开发环境具体怎么搭建我这里就不详细说了,如有需要我后面再讲 . PhoneGap 官方地址有详细说明:http://www.phonegap.com. 在 ...

  7. Gridview中的选择、删除、编辑、更新、取消留着备用。

    后台程序: public partial class tw2 : System.Web.UI.Page{    protected void Page_Load(object sender, Even ...

  8. vue获取dom元素注意问题

    mounted(){ setTimeout(()=>{ this.contentToggle(); },1000) }, methods:{ contentToggle(){ console.l ...

  9. vue二级联动select

    <div> <span>所在区域</span> <select name="" v-model="country"&g ...

  10. 分页功能实现之通过ajax实现表单内容刷新

    拿代码来说话 我们的需求就是点击翻页功能,实现表格内容局部刷新且能够翻到对应的页面上,不明白? 那么就看看下面的图,需要达到的效果如下所示: 现在要实现的功能就是把红线框起来的表单内容 在点击翻页的时 ...