ITPub博客

首页 > > > CommonTwo

CommonTwo

作者:友哥 时间:2017-02-14 22:45:00 0 删除 编辑
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

 

原文作者:;如有侵权,请联系管理员删除。

下一篇: uint16
请登录后发表评论 登录
全部评论

注册时间:2020-05-20

  • 博文量
    276
  • 访问量
    1000