Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
jxtxzzw
Coding
Commits
3884e823
Commit
3884e823
authored
Aug 25, 2021
by
jxtxzzw
Browse files
Update README.md, LeetCode/14.java files
parent
408db178
Pipeline
#433
passed with stage
in 33 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
LeetCode/14.java
0 → 100644
View file @
3884e823
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
;
}
}
README.md
View file @
3884e823
...
...
@@ -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 |
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment