標籤:log string case java 字母 lis [] bit logs
1 public class Solution { 2 public String[] findWords(String[] words) { 3 List<String> oneRowWords = new ArrayList<String>(); 4 String[] keyboard = {"qwertyuiop","asdfghjkl","zxcvbnm"}; 5 for(String word : words) { 6 String realWord = word; 7 word = word.toLowerCase();//每個字母變為小寫 8 char[] strBit = word.toCharArray(); 9 int count = 0;10 for(char ch : strBit) {11 if(keyboard[0].indexOf(strBit[0]) != -1) {//第一個字母在第一排12 if(keyboard[0].indexOf(ch) == -1) {//其他字母必須也在第一排 否則跳過13 break;14 }15 }else if(keyboard[1].indexOf(strBit[0]) != -1) {//第一個字母在第二排16 if(keyboard[1].indexOf(ch) == -1) {17 break;18 }19 }else if(keyboard[2].indexOf(strBit[0]) != -1) {//第一個字母在第三排20 if(keyboard[2].indexOf(ch) == -1) {21 break;22 }23 }24 count ++;25 }26 if(count == strBit.length) {27 oneRowWords.add(realWord);28 }29 }30 String[] oneRowWordsArray = new String[oneRowWords.size()];31 for(int i=0; i<oneRowWords.size(); i++){32 oneRowWordsArray[i] = oneRowWords.get(i);33 }34 35 return oneRowWordsArray;36 }37 }
leetcode Keyboard Row500 Java