更新 Solution.java

master
wangsiyuan 2023-09-06 12:00:57 +08:00
parent e20fbc3713
commit ec10ce6c8a
1 changed files with 20 additions and 0 deletions

View File

@ -105,4 +105,24 @@ public class Solution {
String result = Arrays.stream(nums1).mapToObj(String::valueOf).collect(Collectors.joining(",", "[", "]")); String result = Arrays.stream(nums1).mapToObj(String::valueOf).collect(Collectors.joining(",", "[", "]"));
System.out.println(result); System.out.println(result);
} }
public static String longestCommonPrefix(String[] strs) {
// ["flower","flow","flight"]
int maxPrefix = 0;
int index = 0;
StringBuilder temp = new StringBuilder();
if (strs != null){
for (int i = 0; i < strs.length; i++) {
if (strs[i] != ""){
for (int j = 0; j < strs[i].length() && j < index; j++) {
temp.append(strs[i].charAt(index));
break;
}
} else {
return "";
}
}
}
return "";
}
} }