Leetcode_27 Remove Element
2015-05-31 11:50
288 查看
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.
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.
#include<stdio.h> int removeElement(int *nums,int numsSize,int val) { int count=0; int i; for(i=0;i<numsSize;i++) { if(*(nums+i)!=val) { *(nums+i-count)=*(nums+i); } else { count++; } } return (numsSize-count); } int main(void) { int a[]={1,2,3,4,1,2,3,6}; int t=removeElement(a,8,1); int i; printf("length %d\n",t); for(i=0;i<t;i++) { printf("%d",a[i]); } }
相关文章推荐
- MYSQL CAST
- Java Reflection - Methods
- HDU 5247 找连续数(RMQ+滑窗)
- 国内外科技博客
- Java Reflection - Classes
- linux文件系统基础知识
- 软件版本号扫盲——Beta RC Preview release等
- Java Reflection - Constructors
- 网页元素居中攻略记_(4)用CSS3属性让元素水平垂直居中
- 状态机,层次状态机和行为树的区别以及联系
- 网页元素居中攻略记_(4)用CSS3属性让元素水平垂直居中
- iOS UIControl
- Ubuntu: Use crontab to execute a job periodically
- 反射0-Java Reflection Tutorial
- MySQL 安装
- Gaussian Mixture Model
- SVN中Branch的创建与合并
- [Objective-C]多态的方式--重写、重载
- 算法导论Part3: 二叉搜索树
- C程序增加自定义的error输出/打印函数