JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

same as Remove Duplicates from Sorted Array

 1 public class Solution {
 2     public int removeElement(int[] A, int elem) {
 3         // IMPORTANT: Please reset any member data you declared, as
 4         // the same Solution instance will be reused for each test case.
 5         if(A == null||A.length < 1)
 6             return 0;
 7         int slowrunner = -1;
 8         int fastrunner = 0;
 9         while(fastrunner < A.length)
10         {
11             if(A[fastrunner] == elem)
12             {
13                 fastrunner++;
14             }
15             else
16             {
17                 A[++slowrunner] = A[fastrunner++];
18             }
19         }
20         return slowrunner+1;
21     }
22 }

 

posted on 2013-11-05 15:35  JasonChang  阅读(167)  评论(0编辑  收藏  举报