LeetCode Remove Element
来源:互联网 发布:软件微电子 综合信息 编辑:程序博客网 时间:2024/06/05 21:07
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.
题意:给出一个数组和一个数,删除数据组中的这个数,返回新的数组的长度
思路:用一个下标cnt,遍历数组,如果当前的数等于要删除的数就继续,否则就将当前数赋值给a[cnt],同时将cnt加1
public class Solution { public int removeElement(int[] A, int elem) { int cnt = 0; for (int i = 0, len = A.length; i < len; i++) { if (A[i] == elem) continue; else A[cnt++] = A[i]; } return cnt; }}
0 0
- LeetCode:Remove Element
- LeetCode: Remove Element
- [Leetcode] Remove Element
- LeetCode: Remove Element
- leetcode 39: Remove Element
- [LeetCode] Remove Element
- Leetcode: Remove Element
- Leetcode:Remove Element
- Leetcode:Remove Element
- Leetcode:Remove Element
- [LeetCode]Remove Element
- LeetCode-Remove Element
- LeetCode - Remove Element
- LeetCode | Remove Element
- leetcode之Remove Element
- LeetCode - Remove Element
- LeetCode: Remove Element
- 【LeetCode】Remove Element
- HDU 1720 A+B Coming
- 性能分析工具-JProfiler
- 网络流
- Android开发环境搭建(Eclipse_Windows下)
- lua学习
- LeetCode Remove Element
- 亚克力
- C#基础 之 初始调试
- 填空
- POJ3744(概率dp+矩阵快速幂)
- 通知栏清理与查询
- solr 简单搭建 数据库数据同步(待续)
- (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY)讲解
- html相关笔记,我所不知道的,没注意到的,或者称之为常识...