Remove Element
来源:互联网 发布:html5 360全景源码 编辑:程序博客网 时间:2024/06/05 23:42
Question: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.
Solution:
public class Solution { public int removeElement(int[] A, int elem) { int newLen = A.length; int len = A.length; int start = 0; int end = len - 1; while(start < newLen){ if(A[start] == elem){ A[start] = A[end]; A[end] = elem; end --; newLen --; } else{ start ++; } } return newLen; } }
0 0
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Remove Element
- Java面向对象——继承
- 关于Android横竖屏布局
- 思考c++中rand()函数产生随机数需不需要srand()的发现
- Frenquency == 4
- 电感 电容耦合的判断
- Remove Element
- Collection Iterator
- 【java初学笔记1】关于继承的一些要点
- 和安全有关的那些事(非对称加密、数字摘要、数字签名、数字证书、SSL、HTTPS及其他)
- 设计模式(C++版)之(prototype) 原型模式
- OpenRISC和Orpsoc在DE2-115上的的bootup实验
- Roman to Integer
- 实现3个按钮的回调函数
- 标准系统安装60