zoukankan      html  css  js  c++  java
  • Leetcode500

    leetcode 500 键盘侠

    这道题我的思想是,找一个相对应的映射,从而把24个字母都映射到HashMap上,从而便于自己查找。

    以下便是代码:

    public String[] findWords(String[] words) {
    
        
        int count=0;
        boolean []pos=new boolean[words.length];
        int index=0;
        for(int i=0;i<words.length;i++){
            if(test(words[i])){
                pos[i]=true;
                count++;
            }
        }
        String[]ans=new String[count];
        for(int i=0;i<pos.length;i++){
            if(pos[i]){
                ans[index++]=words[i];
            }
        }
        return ans;
    
    }
    public boolean test(String str){
        java.util.HashMap<Character,Integer>map;
        map=new java.util.HashMap<>();
        String []word={"qwertyuiopQWERTYUIOP","asdfghjklASDFGHJKL","zxcvbnmZXCVBNM"};
        for(int i=0;i<word.length;i++){
            for(int j=0;j<word[i].length();j++){
                map.put(word[i].charAt(j),i+1);
            }
        }
        if(str==null||str.length()<0)
            return false;
        int index=map.get(str.charAt(0));
        for(int i=1;i<str.length();i++){
            if(index!=map.get(str.charAt(i)))
                return false;
        }
        return true;
    }
    
    
    这是小睿的博客,如果需要转载,请标注出处啦~ヾ(≧▽≦*)o谢谢。
  • 相关阅读:
    《父亲写的散文诗》--许飞
    python 解数独
    github key already in use
    openwrt ddns绑定域名
    hexo 长期后台运行
    修复云服务器rpm无法使用的问题
    vim 取消筛选高亮
    力扣 2021.02.25 最长公共前缀
    [模板]-Manacher
    背包问题回顾
  • 原文地址:https://www.cnblogs.com/Yunrui-blogs/p/12303958.html
Copyright © 2011-2022 走看看