Remove element
来源:互联网 发布:网络通信公司简介 编辑:程序博客网 时间:2024/05/30 23:03
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 int removeElement(int[] A, int elem) { int i = -1, j = 0; while (i < A.length && j < A.length) { if (A[j] == elem) { j++; } else { A[++i] = A[j++]; } } return i+1; }
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
- power of the test
- Is the “*apply” family really not vectorized?
- POJ_2513_Colored Sticks(欧拉路+字典树)
- How to distinguish between strings in heap or literals?
- 深入理解内存地址
- Remove element
- java 多线程学习笔记之 线程互斥
- ******************** C语言的基础 ********************
- sorting - shell sort
- ******************** 注释,标示符,关键字 ********************
- Second Highest Salary
- ******************** 常 量 ********************
- ******************** 变 量 ********************
- ******************** scanf函数 ********************