|
@@ -0,0 +1,33 @@
|
|
|
+var rows map[rune]int = map[rune]int{
|
|
|
+ 'A': 1, 'S': 1, 'D': 1, 'F': 1, 'G': 1, 'H': 1, 'J': 1, 'K': 1, 'L': 1,
|
|
|
+ 'Z': 2, 'X': 2, 'C': 2, 'V': 2, 'B': 2, 'N': 2, 'M': 2,
|
|
|
+}
|
|
|
+
|
|
|
+func findWords(words []string) (res []string) {
|
|
|
+ for i := range words {
|
|
|
+ if isInOneRow(words[i]) {
|
|
|
+ res = append(res, words[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func isInOneRow(s string) bool {
|
|
|
+ res := 0
|
|
|
+ for _, r := range s {
|
|
|
+ ch := toUpper(r)
|
|
|
+ if val, ok := rows[ch]; ok {
|
|
|
+ res |= val
|
|
|
+ } else {
|
|
|
+ res |= 4
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res == 1 || res == 2 || res == 4
|
|
|
+}
|
|
|
+
|
|
|
+func toUpper(r rune) rune {
|
|
|
+ if 'a' <= r {
|
|
|
+ return rune(r - 32)
|
|
|
+ }
|
|
|
+ return r
|
|
|
+}
|