package longestprefix import ( "strings" ) func LongestCommonPrefix(strs []string) string { result := "" if len(strs) == 0 { return result } first := strs[0] rest := strs[1:] for i := range first { prefix := first[:i+1] for _, s := range rest { if !strings.HasPrefix(s, prefix) { return result } } result = prefix } return first }