Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8518b4e

Browse files
Some changes in directory structure
1 parent 60b64d1 commit 8518b4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+64
-1752
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public String longestCommonPrefix(String[] strs) {
3+
if (strs == null || strs.length == 0)
4+
return "";
5+
int minLen = Integer.MAX_VALUE;
6+
for (String str : strs)
7+
minLen = Math.min(minLen, str.length());
8+
int low = 1;
9+
int high = minLen;
10+
while (low <= high) {
11+
int middle = (low + high) / 2;
12+
if (isCommonPrefix(strs, middle))
13+
low = middle + 1;
14+
else
15+
high = middle - 1;
16+
}
17+
return strs[0].substring(0, (low + high) / 2);
18+
}
19+
20+
private boolean isCommonPrefix(String[] strs, int len){
21+
String str1 = strs[0].substring(0,len);
22+
for (int i = 1; i < strs.length; i++)
23+
if (!strs[i].startsWith(str1))
24+
return false;
25+
return true;
26+
}
27+
28+
}
-1.61 KB
Binary file not shown.
-1.28 KB
Binary file not shown.

‎Top Interview Questions/Easy/ClimbingStairs.java‎

Lines changed: 0 additions & 23 deletions
This file was deleted.
-956 Bytes
Binary file not shown.

‎Top Interview Questions/Easy/CountAndSay.java‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎Top Interview Questions/Easy/CountPrimes.java‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎Top Interview Questions/Easy/FactorialTrailingZero.java‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎Top Interview Questions/Easy/FirstUniqueChar.java‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎Top Interview Questions/Easy/FizzBuzz.java‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /