1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// @Title: 键盘行 (Keyboard Row)
// @Author: 15816537946@163.com
// @Date: 2021-10-31 18:03:43
// @Runtime: 0 ms
// @Memory: 1.9 MB
func findWords(words []string) []string {
    line1 := map[rune]bool{
        'q':true,
        'w':true,
        'e':true,
        'r':true,
        't':true,
        'y':true,
        'u':true,
        'i':true,
        'o':true,
        'p':true,
    }
    line2 := map[rune]bool{
        'a':true,
        's':true,
        'd':true,
        'f':true,
        'g':true,
        'h':true,
        'j':true,
        'k':true,
        'l':true,
    }


    ret := make([]string,0)
    for _, s := range words {
        var inline1,inline2, inline3 uint8
        for _,b := range s {
            if b <= 'Z' {
                b += 'z'-'Z'
            }

            if line1[b] {
                inline1 = 1
                continue
            }
            if  line2[b] {
                inline2 = 1
                continue
            }
            inline3 = 1
        }
        if inline1+inline2+inline3 == 1 {
            ret = append(ret,s)
        }
    }
    return ret
}