题目: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. Android Studio 出现 Build gradle project info

    导入Android Studio,一直停留在Build gradle project info.主要是因为google被墙,下载gradle很慢,有时候设置下载不成功. 参考链接 http://blo ...

  2. Hadoop(HA)分布式集群部署

    Hadoop(HA)分布式集群部署和单节点namenode部署其实一样,只是配置文件的不同罢了. 这篇就讲解hadoop双namenode的部署,实现高可用. 系统环境: OS: CentOS 6.8 ...

  3. [mysql]ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value

    From: http://m.blog.csdn.net/blog/langkeziju/13511411 我的MySQL版本为5.6.14版本,是二进制包安装的(虽然是二进制包安装的,但是以下问题同 ...

  4. redis集群【转】

    一.环境 系统    CentOS7.0 64位最小化安装 redis1    172.16.1.46    6379,6380 redis2    172.16.1.47    6379,6380 ...

  5. Jenkins的安装配置[转]

    Jenkins的安装配置 一.Jenkins简介 Jenkins 是一个可扩展的持续集成引擎.Jenkins可以帮我们将代码进行统一的编译打包.还可以放到tomcat容器中进行发布.简单来说就是我们通 ...

  6. win7下命令行提示符从C盘进入E盘的文件夹下

    进入E:\papercode\3D-point-cloud-generation-master\3D-point-cloud-generation-master

  7. Java常用类(二)String类详解

    前言 在我们开发中经常会用到很多的常用的工具类,这里做一个总结.他们有很多的方法都是我们经常要用到的.所以我们一定要把它好好的掌握起来! 一.String简介 1.1.String(字符串常量)概述 ...

  8. maven中snapshot快照库和release发布库的区别和作用 (转)

    Maven介绍,包括作用.核心概念.用法.常用命令.扩展及配置 http://www.trinea.cn/android/maven/ 本文来源于铁木箱子的博客http://www.mzone.cc ...

  9. gridview列超链接的几种设置方法

    <asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenera ...

  10. 安装oh my zsh和git插件

    http://macshuo.com/?p=676   --安装oh my zsh http://www.jianshu.com/p/9189eac3e52d https://github.com/r ...