1 parent 87ebbf6 commit 438686dCopy full SHA for 438686d
1 file changed
0014-longest-common-prefix/0014-longest-common-prefix.go
@@ -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