Movatterモバイル変換


[0]ホーム

URL:


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

Commit98f9fe7

Browse files
author
applewjg
committed
Longest CommonPrefix
Change-Id: I0be489b105a37722f5041d40bcfe8f52d5777f32
1 parentb27739d commit98f9fe7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎LongestCommonPrefix.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Author: King, wangjingui@outlook.com
3+
Date: Dec 20, 2014
4+
Problem: Longest Common Prefix
5+
Difficulty: Easy
6+
Source: https://oj.leetcode.com/problems/longest-common-prefix/
7+
Notes:
8+
Write a function to find the longest common prefix string amongst an array of strings.
9+
10+
Solution: ...
11+
*/
12+
publicclassSolution {
13+
publicStringlongestCommonPrefix(String[]strs) {
14+
if (strs.length ==0)returnnewString("");
15+
for(inti =0;i <strs[0].length(); ++i){
16+
for(intj =1;j <strs.length; ++j){
17+
if(i >=strs[j].length() ||strs[j].charAt(i) !=strs[0].charAt(i))
18+
returnstrs[0].substring(0,i);
19+
}
20+
}
21+
returnstrs[0];
22+
}
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp