思路:
// @Title: 最长公共前缀 (Longest Common Prefix)
// @Author: qisiii
// @Date: 2024-04-11 23:52:45
// @Runtime: 1 ms
// @Memory: 40.5 MB
// @comment:
// @flag:
class Solution {
public String longestCommonPrefix(String[] strs) {
StringBuilder stringBuilder=new StringBuilder();
String str=strs[0];
for(int i=0;i<str.length();i++){
for(int j=1;j<strs.length;j++){
if(i>=strs[j].length()||str.charAt(i)!=strs[j].charAt(i)){
return stringBuilder.toString();
}
}
stringBuilder.append(str.charAt(i));
}
return stringBuilder.toString();
}
}