Skip to content

Commit 438686d

Browse files
committed
Time: 2 ms (70.21%), Space: 2.5 MB (69.74%) - LeetHub
1 parent 87ebbf6 commit 438686d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
func longestCommonPrefix(strs []string) string {
2+
common := strs[0]
3+
for _, str := range strs {
4+
if len(common) != len(str) {
5+
if len(common) < len(str) {
6+
common = common[:len(common)]
7+
} else {
8+
common = common[:len(str)]
9+
}
10+
}
11+
for j:=0; j<len(common) && j<len(str); j++ {
12+
if common[j] != str[j] {
13+
common = common[:j]
14+
}
15+
}
16+
}
17+
return common
18+
}

0 commit comments

Comments
 (0)