Solution
public class Solution {
public String longestCommonPrefix(String[] strs) {
if(strs == null || strs.length == 0)
return "";
String prefix = strs[0];
for(int i = 1; i < strs.length; i++) {
int j = 0;
while(j < strs[i].length() && j < prefix.length() && prefix.charAt(j) == strs[i].charAt(j)) {
j++;
}
prefix = prefix.substring(0, j);
}
return prefix;
}
}
Priblem3:
* 循环条件的选取
* 只需要知道位置
Problem2:
* 注意while循环的跳出条件