Compare commits
2 Commits
e20fbc3713
...
755fdc488a
| Author | SHA1 | Date | |
|---|---|---|---|
| 755fdc488a | |||
| 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 "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,18 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class test {
|
public class test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int[] nums1 = new int[]{1,2,3,0,0,0};
|
// int[] nums1 = new int[]{1,2,3,0,0,0};
|
||||||
int m = 3;
|
// int m = 3;
|
||||||
int[] nums2 = new int[]{2,5,6};
|
// int[] nums2 = new int[]{2,5,6};
|
||||||
int n = 3;
|
// int n = 3;
|
||||||
// int[] nums1 = new int[]{1};
|
// int[] nums1 = new int[]{1};
|
||||||
// int m = 1;
|
// int m = 1;
|
||||||
// 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 result = Solution.longestCommonPrefix(strs);
|
||||||
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user