add new solutions
This commit is contained in:
parent
59b71480d4
commit
71189b61cf
8 changed files with 200 additions and 0 deletions
19
solutions/0/q14/solution.go
Normal file
19
solutions/0/q14/solution.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package q14
|
||||
|
||||
func longestCommonPrefix(strs []string) string {
|
||||
minLen := len(strs[0])
|
||||
for i := 1; i < len(strs); i++ {
|
||||
minLen = min(minLen, len(strs[i]))
|
||||
}
|
||||
|
||||
for pfxLen := range minLen {
|
||||
for i := 1; i < len(strs); i++ {
|
||||
if strs[i][pfxLen] != strs[0][pfxLen] {
|
||||
return strs[0][:pfxLen]
|
||||
}
|
||||
}
|
||||
}
|
||||
return strs[0][:minLen]
|
||||
}
|
||||
|
||||
var _ = longestCommonPrefix
|
||||
Loading…
Add table
Add a link
Reference in a new issue