Compare commits
2 Commits
755fdc488a
...
8ce22bbbbb
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ce22bbbbb | |||
| e57ebeadf8 |
@@ -112,16 +112,26 @@ public class Solution {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
StringBuilder temp = new StringBuilder();
|
StringBuilder temp = new StringBuilder();
|
||||||
if (strs != null){
|
if (strs != null){
|
||||||
for (int i = 0; i < strs.length; i++) {
|
for (int k = 0; k < strs[0].length(); k++) {
|
||||||
if (strs[i] != ""){
|
char indexChar = strs[0].charAt(index);
|
||||||
for (int j = 0; j < strs[i].length() && j < index; j++) {
|
for (int i = 1; i < strs.length; i++) {
|
||||||
temp.append(strs[i].charAt(index));
|
if (strs[i] != ""){
|
||||||
break;
|
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 "";
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ public class test {
|
|||||||
// int[] nums2 = new int[]{};
|
// int[] nums2 = new int[]{};
|
||||||
// int n = 0;
|
// int n = 0;
|
||||||
// Solution.merge(nums1,m,nums2,n);
|
// Solution.merge(nums1,m,nums2,n);
|
||||||
String[] strs = new String[]{"flower","flow","flight"};
|
// String[] strs = new String[]{"flower","flow","flight"};
|
||||||
|
String[] strs = new String[]{"abcg","abcecar","abr"};
|
||||||
|
|
||||||
String result = Solution.longestCommonPrefix(strs);
|
String result = Solution.longestCommonPrefix(strs);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user