CommonTwo

public int commonTwo(String[] a, String[] b) {
  int startA=0;
  int startB=0;
  int count=0;
  
  
  while((( startA < a.length ) && ( startB < b.length )))
  {
    if(startA >0){
      if(a[startA].equals(a[startA-1])){
        startA++;
        continue;
      }
    }
    if(startB >0){
      if(b[startB].equals(b[startB-1])){
        startB++;
        continue;
      }
    }
    
    if( a[startA].equals(b[startB]) ){
      count++;
      startA++;
      startB++;
    }
    else if( (a[startA].compareTo(b[startB])) < 0  ){
      startA++;
    }
    else{
      startB++;
    }
    
  }
  return count;
  
}

http://codingbat.com/prob/p100369

 

posted @ 2017-02-14 22:45  友哥  阅读(200)  评论(0编辑  收藏  举报