1 Public classSolution {2 Publicstring[] Findwords (string[] words) {3List<string> onerowwords =NewArraylist<string>();4String[] Keyboard = {"Qwertyuiop", "ASDFGHJKL", "ZXCVBNM"};5 for(String word:words) {6String Realword =Word;7Word = Word.tolowercase ();//each letter becomes lowercase8 Char[] Strbit =Word.tochararray ();9 intCount = 0;Ten for(Charch:strbit) { One if(Keyboard[0].indexof (strbit[0])! =-1) {//first letter in row one A if(Keyboard[0].indexof (ch) = =-1) {//Other letters must also be skipped in the first row otherwise - Break; - } the}Else if(Keyboard[1].indexof (strbit[0])! =-1) {//The first letter is in the second row . - if(Keyboard[1].indexof (ch) = =-1) { - Break; - } +}Else if(Keyboard[2].indexof (strbit[0])! =-1) {//first letter in row three - if(Keyboard[2].indexof (ch) = =-1) { + Break; A } at } -Count + +; - } - if(Count = =strbit.length) { - Onerowwords.add (Realword); - } in } -string[] Onerowwordsarray =Newstring[onerowwords.size ()]; to for(inti=0; I<onerowwords.size (); i++){ +Onerowwordsarray[i] =Onerowwords.get (i); - } the * returnOnerowwordsarray; $ }Panax Notoginseng}
Leetcode Keyboard Row500 Java