Remove Element

发布时间:2017-6-27 6:33:26 编辑 分享查询网我要评论
本篇文章主要介绍了"Remove Element",主要涉及到Remove Element方面的内容,对于Remove Element感兴趣的同学可以参考一下。

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. Solution:public class Solution { public int removeElement(int[] A, int elem) { int newLen = A.length; int len = A.length; int start = 0; int end = len - 1; while(start < newLen){ if(A[start] == elem){ A[start] = A[end]; A[end] = elem; end --; newLen --; } else{ start ++; } } return newLen; } }

上一篇:电感 电容耦合的判断
下一篇:Adb failed to restart! Make sure the plugin is properly configured.


关键词: Remove Element