Chinaunix首页 | 论坛 | 博客
  • 博客访问: 254737
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-04-09 12:24:02

//Remove Element Total Accepted: 50575 Total Submissions: 155945 My Submissions Question Solution 
//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 class RemoveElement {


public static void main(String[] args) {
// TODO 自动生成的方法存根


}
public int removeElement(int[] A, int elem) {
       if(A.length==0)
return 0;

int j=0;
       for(int i=0;i         if(elem!=A[i]){
        A[j]=A[i];
        j++;
        }
       
       }
       return j;
   }


}

阅读(713) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~