mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 08:02:30 +08:00
28 lines
475 B
Go
28 lines
475 B
Go
package leetcode
|
|
|
|
import "strings"
|
|
|
|
func findWords500(words []string) []string {
|
|
rows := []string{"qwertyuiop", "asdfghjkl", "zxcvbnm"}
|
|
output := make([]string, 0)
|
|
for _, s := range words {
|
|
if len(s) == 0 {
|
|
continue
|
|
}
|
|
lowerS := strings.ToLower(s)
|
|
oneRow := false
|
|
for _, r := range rows {
|
|
if strings.ContainsAny(lowerS, r) {
|
|
oneRow = !oneRow
|
|
if !oneRow {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if oneRow {
|
|
output = append(output, s)
|
|
}
|
|
}
|
|
return output
|
|
}
|