728x90
반응형
문제
반응형
풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
class Solution {
public String longestCommonPrefix(String[] strs) {
int min = 201;
for(int i=0; i<strs.length; i++) {
if(strs[i].length() < min) {
min=strs[i].length();
}
}
String pref = "";
for(int i=0; i<min; i++) {
for(int j=0; j<strs.length-1; j++) {
if(strs[j].charAt(i) != strs[j+1].charAt(i)) {
return pref;
}
}
pref += strs[0].charAt(i);
}
return pref;
}
}
|
cs |
728x90
반응형
'[JAVA] LeetCode > Easy' 카테고리의 다른 글
[LeetCode/릿코드] 27. Remove Element (0) | 2023.01.13 |
---|---|
[LeetCode/릿코드] 26. Remove Duplicates from Sorted Array (0) | 2023.01.12 |
[LeetCode/릿코드] 13. Roman to Integer (0) | 2023.01.09 |
[LeetCode/릿코드] 9. Palindrome Number (0) | 2023.01.09 |
[LeetCode/릿코드] 1. Two Sum (0) | 2022.12.30 |