Commit 3884e823 authored by jxtxzzw's avatar jxtxzzw
Browse files

Update README.md, LeetCode/14.java files

parent 408db178
Pipeline #433 passed with stage
in 33 seconds
class Solution {
public String longestCommonPrefix(String[] strs) {
if (strs == null || strs.length == 0) {
return "";
}
int minLength = strs[0].length();
for (String s : strs) {
minLength = Math.min(minLength, s.length());
}
int l = 0;
int r = minLength;
while (l <= r) {
int mid = (l + r) / 2;
String candidate = strs[0].substring(0, mid);
if (bs(candidate, strs)) {
l = mid + 1;
} else {
r = mid - 1;
}
}
return strs[0].substring(0, (l + r) / 2);
}
private boolean bs(String candidate, String[] strs) {
System.out.println(candidate);
for (String s : strs) {
if (!s.startsWith(candidate)) {
return false;
}
}
return true;
}
}
......@@ -280,6 +280,7 @@ Use search to find what you want to see. Recommended to use https://record.jxtxz
| LeetCode | 11 | Container With Most Water | 双指针 | 暴力 | |
| LeetCode | 12 | Integer to Roman | | | java |
| LeetCode | 13 | Roman to Integer | | | java |
| LeetCode | 14 | Longest Common Prefix | | 二分 | java |
| LeetCode | 15 | 3Sum | | | java |
| LeetCode | 17 | Letter Combinations of a Phone Number | | 递归 | java |
| LeetCode | 18 | 4Sum | | | java |
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment