Skip to content

Commit 6551285

Browse files
Merge pull request #2133 from CodingTestStudy2/이진희
[이진희] 2026/10/05
2 parents c273e1c + 3c1e344 commit 6551285

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public String longestCommonPrefix(String[] strs) {
3+
StringBuilder sb = new StringBuilder();
4+
5+
String base = strs[0];
6+
7+
for(int i=0; i<base.length(); i++) {
8+
char c = base.charAt(i);
9+
for(int j=1; j<strs.length; j++) {
10+
if((strs[j].length()-1)<i || strs[j].charAt(i) != c) {
11+
return sb.toString();
12+
}
13+
}
14+
sb.append(c);
15+
}
16+
17+
return sb.toString();
18+
}
19+
}

0 commit comments

Comments
 (0)