/**
* 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. 利用Linux信号SIGUSR1调试程序

    Linux嵌入式由于诸多的限制,调试方法有限,常常出现面对Bug束手无策的情况,现在介绍一种通过信号处理对Linux嵌入式应用程序进行调试的方法. linux中一共有32种信号,在/usr/inclu ...

  2. 选择困难症的福音——团队Scrum冲刺阶段-Day 3

    选择困难症的福音--团队Scrum冲刺阶段-Day 3 今日进展 编写提问部分 做了不同问题所对应的游戏选项,但关于游戏分类的界面还没有做完 登陆注册界面 更改ui界面,ui界面终于变好看了:) 学习 ...

  3. POJ 3107.Godfather 树形dp

    Godfather Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7536   Accepted: 2659 Descrip ...

  4. KD-树(上)

    来自于https://zhuanlan.zhihu.com/p/23966698 思路篇 导语:kd 树是一种二叉树数据结构,可以用来进行高效的 kNN 计算.kd 树算法偏于复杂,本篇将先介绍以二叉 ...

  5. 第一个VS2015 Xaramin Android项目

    20170323新增:VS环境配置 打开VS,菜单栏选工具(Tools) 选项\ 一般有2个地方需要修改 1 2 新建第一个项目,什么都没有修改的情况下(已经配置好环境变量)直接运行,会发现如下错误: ...

  6. Scrum冲刺阶段2

    成员今日完成的任务 人员 任务 何承华 后端设计 陈宇 后端设计 丁培辉 后端设计 温志铭 主页面的设计 杨宇潇 主页面的设计 张主强 服务器构建 成员遇到的问题 人员 问题 何承华 暂无 陈宇 暂无 ...

  7. 树上差分——点差分裸题 P3128 [USACO15DEC]最大流Max Flow

    讲解: https://rpdreamer.blog.luogu.org/ci-fen-and-shu-shang-ci-fen #include <bits/stdc++.h> #def ...

  8. Java中资料的上传与下载

    1.导架包 <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons ...

  9. Localization

    Localization (using Histogram Filters) 定位指的是在传感器和移动之间来回的迭代,使得能够保持跟踪目标对象的位置.方向和速度. 这篇将写一个程序来实施定位,与GPS ...

  10. Learning Rust - Syntax

    Rust is another compiling language that may replace the position of C/C++ in server filed. It runs f ...