mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 16:36:41 +08:00
17 lines
276 B
Go
17 lines
276 B
Go
package leetcode
|
|
|
|
func longestCommonPrefix(strs []string) string {
|
|
prefix := strs[0]
|
|
|
|
for i := 1; i < len(strs); i++ {
|
|
for j := 0; j < len(prefix); j++ {
|
|
if len(strs[i]) <= j || strs[i][j] != prefix[j] {
|
|
prefix = prefix[0:j]
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return prefix
|
|
}
|