Compare commits
No commits in common. "8ce22bbbbbc52f16668a0b16e998d645e9c681f6" and "755fdc488a1b6d6a60cbeba4822a6663ac2134dd" have entirely different histories.
8ce22bbbbb
...
755fdc488a
|
|
@ -112,26 +112,16 @@ public class Solution {
|
|||
int index = 0;
|
||||
StringBuilder temp = new StringBuilder();
|
||||
if (strs != null){
|
||||
for (int k = 0; k < strs[0].length(); k++) {
|
||||
char indexChar = strs[0].charAt(index);
|
||||
for (int i = 1; i < strs.length; i++) {
|
||||
if (strs[i] != ""){
|
||||
for (int j = 0; j < 1; j++) {
|
||||
char crrChar = strs[i].charAt(index);
|
||||
if (indexChar != crrChar){
|
||||
return String.valueOf(temp);
|
||||
}
|
||||
if (i == strs.length- 1){
|
||||
temp.append(crrChar);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return "";
|
||||
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 "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ public class test {
|
|||
// int[] nums2 = new int[]{};
|
||||
// int n = 0;
|
||||
// Solution.merge(nums1,m,nums2,n);
|
||||
// String[] strs = new String[]{"flower","flow","flight"};
|
||||
String[] strs = new String[]{"abcg","abcecar","abr"};
|
||||
|
||||
String[] strs = new String[]{"flower","flow","flight"};
|
||||
String result = Solution.longestCommonPrefix(strs);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue