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.

中文:给定一个数组和一个数值,去除这个数值全部出现位置,并返回新数组的长度。

元素的顺序能够改变。除了新的长度,你留下什么并不重要。

Java

	public static int removeElement(int[] A, int elem) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < A.length; i++) {
if (A[i] == elem)
continue;
list.add(A[i]);
}
for (int i = 0; i < list.size(); i++)
A[i] = list.get(i);
return list.size();
}

LeetCode——Remove Element的更多相关文章

  1. [LeetCode] Remove Element 分析

    Remove Element算是LeetCode的一道水题,不过这题也有多种做法,现就我所知的几种做一点讨论. 题目链接:https://leetcode.com/problems/remove-el ...

  2. [LeetCode] Remove Element题解

    Remove Element: Given an array and a value, remove all instances of that value in place and return t ...

  3. [LeetCode] Remove Element 移除元素

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

  4. LeetCode Remove Element

    原题链接在这里:https://leetcode.com/problems/remove-element/ 题目: Given an array and a value, remove all ins ...

  5. [LeetCode] Remove Element (三种解法)

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

  6. [Leetcode] remove element 删除元素

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

  7. leetcode Remove Element python

    class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] ...

  8. LeetCode Remove Element删除元素

    class Solution { public: int removeElement(int A[], int n, int elem) { ]; int i,num=n; ;i<n;i++){ ...

  9. [Leetcode][Python]27: Remove Element

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 27: Remove Elementhttps://oj.leetcode.c ...

随机推荐

  1. cmd下运行java文件时,找不到或无法加载主类的解决方法

    最近再看java,却被一个看似很基础的hellorworld头疼了十几分钟,百度了一下,若你在cmd下编辑及运行.java文件时报错,解决方案如下,如图所示:

  2. 转:PHP – Best Practises

    原文来自于:http://thisinterestsme.com/php-best-practises/ There are a number of good practises that you s ...

  3. bzoj 2693: jzptab 线性筛积性函数

    2693: jzptab Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 444  Solved: 174[Submit][Status][Discus ...

  4. textarea宽度、高度自动适应处理方法

    textarea自动高度 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http: ...

  5. uvalive 6185

    高斯消元,以前从来没写过,今天的模拟比赛里面,添琦给了我一个模板! 虽然是个裸的,但是因为从来没写过,一个小细节竟然搞了我几个小时: 终于最后在小珺同志的帮助下成功a掉了,太开心了! 存一下,作为模板 ...

  6. Myeclipse2013 SVN安装方法以及项目上传到svn服务器

    1. 打开 Myeclipse 工具栏下的Help下的Install from Site 2.打开后弹出窗口, 并点击Add标签,如下图: 3.现在是最重要的一步,填写相关信息. 在对话框Name输入 ...

  7. ANDROID_MARS学习笔记_S05_006_距离传感器

    import android.app.Activity; import android.content.Context; import android.hardware.Sensor; import ...

  8. 【HDOJ】1175 连连看

    BFS.wa了一下午,原来是YES,写成了Yes. #include <iostream> #include <cstdio> #include <cstring> ...

  9. 【转】android获取屏幕宽度和高度

    原文网址:http://www.cnblogs.com/howlaa/p/4123186.html 1. WindowManager wm = (WindowManager) getContext() ...

  10. Linux内存调试工具初探-MEMWATCH

    C 语言作为 Linux 系统上标准的编程语言给予了我们对动态内存分配很大的控制权.这种自由可能会导致严重的内存管理问题,可能导致程序崩溃或随时间的推移导致性能降级. 内存泄漏(即 malloc()  ...