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
原文:http://www.cnblogs.com/youge-OneSQL/p/6399553.html