Skip to content

Commit d213a2a

Browse files
author
Yeqi Tao
committed
Add Soulution.go for 0014.Longest Common Prefix
1 parent b33c397 commit d213a2a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func longestCommonPrefix(strs []string) string {
2+
result := ""
3+
for i, v := range strs {
4+
if i == 0 {
5+
result = v
6+
}
7+
index := 0
8+
for index < len(result) && index < len(v) && result[index] == v[index] {
9+
index++
10+
}
11+
result = result[:index]
12+
}
13+
return result
14+
}

0 commit comments

Comments
 (0)