Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luojiyin1987/852e89a4f1a8affb6b6242023b2dcfc1 to your computer and use it in GitHub Desktop.
Save luojiyin1987/852e89a4f1a8affb6b6242023b2dcfc1 to your computer and use it in GitHub Desktop.
Keyboard Row
func findWords(words []string) []string {
var row1 string = "qwertyuiop"
var row2 string = "asdfghjkl"
var row3 string = "zxcvbnm"
var result []string
var startrow1, startrow2, startrow3 int
for _, res := range words {
reslow := strings.ToLower(res)
for _, y := range reslow {
if strings.Contains(row1, string(y)) == true {
startrow1++
} else if strings.Contains(row2, string(y)) == true {
startrow2++
} else if strings.Contains(row3, string(y)) == true {
startrow3++
} else {
fmt.Println("nothing")
}
}
if len(res) == startrow1 || len(res) == startrow2 || len(res) == startrow3 {
result = append(result, res)
}
startrow1, startrow2, startrow3 = 0, 0, 0
}
return result
}
func findWords(words []string) []string {
top := "qwertyuiop"
mid := "asdfghjkl"
var words2 []string;
for i := 0; i < len(words); i++ {
count1, count2, count3 := 0,0,0
include := true;
for _, char := range words[i] {
if strings.Contains(top, strings.ToLower(string(char))) {
count1 += 1
} else if strings.Contains(mid, strings.ToLower(string(char))) {
count2 += 1
} else {
count3 += 1
}
if (count1 > 0 && count2 > 0) || (count1 > 0 && count3 > 0) || (count2 > 0 && count3 > 0) {
include = false;
break;
}
}
if include {
words2 = append(words2, words[i])
}
}
return words2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment