zoukankan      html  css  js  c++  java
  • 500. Keyboard Row

    Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.

    Example 1:

    Input: ["Hello", "Alaska", "Dad", "Peace"]
    Output: ["Alaska", "Dad"]

    My Solution:

    public class Solution {
        public String[] findWords(String[] words) {
            String q = "[qwertyuiop]+";
            String a = "[asdfghjkl]+";
            String z = "[zxcvbnm]+";
    
            List<String> list = new ArrayList<String>();
            
            for(int i = 0; i < words.length; i++){
                if(words[i].toLowerCase().matches(q) || words[i].toLowerCase().matches(a) || words[i].toLowerCase().matches(z)){
                    list.add(words[i]);
                }    
            }
            
            String[] arr = new String[list.size()];
            return list.toArray(arr);
        }
    }
  • 相关阅读:
    奇异值分解
    特征值和特征向量
    矩阵
    矢量化
    符号数组
    通用函数
    数据平滑
    多项式拟合
    协方差/相关矩阵/相关系数
    json
  • 原文地址:https://www.cnblogs.com/luojunc/p/6423738.html
Copyright © 2011-2022 走看看