/**
* Source : https://oj.leetcode.com/problems/remove-element/
*
* Created by lverpeng on 2017/7/12.
*
* 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.
*/
public class RemoveElement { /**
* 判断不等于value的值个数
* @param num
* @param value
* @return
*/
public int remove (int[] num, int value) {
int pos = 0;
for (int i = 0; i < num.length; i++) {
if (num[i] != value) {
pos ++;
}
}
return pos;
} public static void main(String[] args) {
RemoveElement removeElement = new RemoveElement();
int[] num = new int[]{1,2,3,4,5,5,6};
System.out.println(removeElement.remove(num, 5));
}
}

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 删除元素

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

  8. leetcode Remove Element python

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

  9. LeetCode Remove Element删除元素

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

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

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

随机推荐

  1. 如何将JetBrains IDE 光标由块变为 |

    1 设置中确认未勾选 2 安装了IdeaVim 插件,将其改为未选中状态,或者 ⌥ + ⌘ +  v 将其关闭

  2. ----这是一个register code----

    这是一个register code,是需要用到<input>标签下的6个标签(?应该是标签喔) 然后附上代码 <html ><head><title>注 ...

  3. bzoj4555(多项式求逆解法)

    //和以前写的fft不太一样,可能是因为要取模?? #include<iostream> #include<cstring> #include<cmath> #in ...

  4. SWPU-ACM集训队周赛之组队赛(3-11) E题题解

    点这里去做题 %*c  读入时跳过一位,本题中即跳过"-"; #include<stdio.h> int run(int x) //判断闰年 { ; ==&&a ...

  5. spring redis @Cacheable注解使用部分错误及无效原因

    spring redis @Cacheable注解使用部分错误及无效原因 说明:     spring项目用到redis注解无效,解决问题中遇到一堆BUG,各种搜索,看了许多错误解决方案一一测试,对于 ...

  6. Android-Java-静态变量与静态方法&普通变量与普通方法(内存图 完整版)

    描述Student对象: package android.java.oop12; // 描述Student对象实体 public class Student { private String name ...

  7. ubuntu16.04安装最新版docker、docker-compose、docker-machine

    安装前说明: 本文将介绍在ubuntu16.04系统下安装和升级docker.docker-compose.docker-machine. docker:有两个版本:docker-ce(社区版)和do ...

  8. iOS逆向之Reveal

    Reveal是一个强大的UI分析工具,使用它可以查看各个界面的视图层级,在解决界面显示问题时非常有用.它最大的特点就是非常直观,查看UI布局的时候非常方便. 我们知道,Reveal官网提供的方法只能监 ...

  9. Yii2 Template 组件框架集封装

    项目简介: Yii2_Template是一个“提供大多数PHP常用的组件去集合成的一套基于Yii2的项目框架”. 该项目是一款秉着提高 开发效率.降低开发成本,遵循高拓展,高可用的原则的进行开发的框架 ...

  10. [Swift]扩展UIImage :获取图片指定像素的颜色值

    对[UIImage]进行扩展 import UIKit extension UIImage{ /** 根据坐标获取图片中的像素颜色值 */ subscript (x: Int, y: Int) -&g ...