Open Clear2 opened 4 years ago
func longestCommonPrefix(strs []string) string { if len(strs) == 0 { return "" } if len(strs) == 1 { return strs[0] } prefix := strs[0] for _, k := range strs { fmt.Println(k) for strings.Index(k, prefix) != 0 { if len(prefix) == 0 { return "" } prefix = prefix[:len(prefix) -1] } } return prefix }