更新 Solution.java
parent
e20fbc3713
commit
ec10ce6c8a
|
|
@ -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 "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue