Remove Element
来源:互联网 发布:运气一直很差知乎 编辑:程序博客网 时间:2024/05/16 18:36
题目:
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.
如果数组中有某个值,则删除这个值,并返回新的数组;
思路:
正常思路,循环判断
代码:
class Solution {public: int removeElement(int A[], int n, int elem) { if(n==0 && *A==NULL) { return 0; } else { int count=0; for(int i=0;i<n;i++) { if(A[i]==elem) { count++; } else if(count>0) { A[i-count]=A[i]; } } return n-count; } }};
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
- 学习ASP.NET MVC5框架揭秘笔记-ASP.NET路由(一)
- JavaScript简单抽奖程序的实现及代码
- CUDA 之基础
- 简单使用achartengine绘制折线图
- 如何检查 Android 应用的内存使用情况
- Remove Element
- Android 自定义控件玩转字体变色 打造炫酷ViewPager指示器
- quick-cocos2d-x的热更新机制实现<四>update包(lua)(上)
- 设计模式之六大原则(转载)
- 心形进度条
- 第十一周项目2——职员有薪水了
- JAVA菜鸟入门(15) static method/ field与normal method/field的相互调用关系
- 第9周项目1 复数类中的运算符重载(续)
- 【Java编程】Dom4j解析和生成XML文档