leetcode — remove-element
/**
* 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的更多相关文章
- [LeetCode] Remove Element 分析
Remove Element算是LeetCode的一道水题,不过这题也有多种做法,现就我所知的几种做一点讨论. 题目链接:https://leetcode.com/problems/remove-el ...
- [LeetCode] Remove Element题解
Remove Element: Given an array and a value, remove all instances of that value in place and return t ...
- [LeetCode] Remove Element 移除元素
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- LeetCode Remove Element
原题链接在这里:https://leetcode.com/problems/remove-element/ 题目: Given an array and a value, remove all ins ...
- [LeetCode] Remove Element (三种解法)
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- LeetCode——Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- [Leetcode] remove element 删除元素
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- leetcode Remove Element python
class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] ...
- LeetCode Remove Element删除元素
class Solution { public: int removeElement(int A[], int n, int elem) { ]; int i,num=n; ;i<n;i++){ ...
- [Leetcode][Python]27: Remove Element
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 27: Remove Elementhttps://oj.leetcode.c ...
随机推荐
- 时间戳转中国人能看得懂的日期格式 yy-mm-dd
很多项目都会用到时间戳的转换 说实话 我现在的这家公司超级好 因为后太要求传数据的时候竟然可以是时间戳的格式 我觉得我好幸福 哈哈哈 不过 等后台转给你数据的时候很多时候都是时间戳 这时候就得前端转 ...
- 综合评价模型C++实现
1 综合评价模型建立步骤 综合评价模式是一种对一个或多个系统进行评价的模型.一般分为如下几个步骤: 选取评价指标,指标的选取应该具有独立性和全面性. 得到m×n测量矩阵,每一行表示一个带评价系统(共m ...
- typescript里面调用javasript
index.html 里面加入函数: function tellYou() { egret.log("tell you."); javascript:android.funA(); ...
- [转]ArcGIS for Silverlight:关于尝试连接到REST端点时发生安全异常的解决方案
Silverlight跨域策略: 要从远程服务器访问数据,远程服务器需要在 web 服务器的根目录下放置一个 clientaccesspolicy.xml 文件(例如 c:\inetpub\wwwro ...
- ABP框架系列之十九:(Debugging-调试)
While it's not generally needed, you may want to step into ABP's source code while you debugging you ...
- python repr()和str()
两者功能差不多,都是把对象转为字符串表示形式,但是也有区别,repr()之后再eval()可以转为原型,但str()只能保证大多数,不能100% 其中主要的 差别在与 字符串对象本身,比如 a = ' ...
- 【转】comparable Interface
作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ 1.什么是Comparable接口 此接口强行对实现它的每个类的对象进行整体排序.此排序被称为该类的自然排序 , ...
- JAVA核心问题(一)反射之引言 构造函数
反射,简单来说,就是在运行时获取Class对象的所有属性和方法,无论公有私有.虽然是一个基础问题,在这里还是全面的记录一下,认真对待! 获取构造函数 构造函数大致分为两种,public和非public ...
- [ 9.28 ]CF每日一题系列—— 940A规律构造
Description: 输入a,b,x,给你a个0,b个1,你要给出一个组合,让这个组合里存在x位,使得这x为和其x+1位不相等 Solution: 因为肯定有一个正确的答案,所以钻了一下空子,贪心 ...
- 16.IO之其他流
第一 打印流 一.概述: 该流提供了打印方法,可以将各种数据类型的数据都原样打印 原理; x<=3; x++){ al.add(new FileInputStream(x+".txt ...