반응형
leetcode.com/problems/longest-common-prefix/
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
char * longestCommonPrefix(char ** strs, int strsSize){
if(strsSize==0) return "";
char* rst = (char*)malloc(sizeof(char)*201);
char cmp;
int p=0;
while(cmp = strs[0][p]){
rst[p] = cmp;
for(int i=1 ; i<strsSize ; i++){
if(strs[i][p]!=cmp) {
rst[p] = 0;
return rst;
}
}
p++;
}
rst[p] = 0;
return rst;
}
|
cs |
반응형
'코딩테스트 > Leetcode' 카테고리의 다른 글
Leetcode - [Easy]14. Longest Common Prefix (0) | 2021.04.04 |
---|---|
Leetcode - [Medium]6. ZigZag Conversion (0) | 2021.03.25 |
Leetcode - [Easy]13. Roman to Integer (0) | 2021.03.14 |
Leetcode - [Medium]3. Longest Substring Without Repeating Characters (0) | 2021.03.07 |
Leetcode - [Medium]2. Add Two Numbers (0) | 2021.03.04 |