zoukankan      html  css  js  c++  java
  • 288. Unique Word Abbreviation

        /*
         * 288. Unique Word Abbreviation
         * 2016-7-1 by Mingyang
         * 这个题目的解释也是醉了,不解释
         */
         class ValidWordAbbr {
                HashMap<String, String> map;
                public ValidWordAbbr(String[] dictionary) {
                    map = new HashMap<String, String>();
                    for(String str:dictionary){
                        String key = getKey(str);
                        // If there is more than one string belong to the same key
                        // then the key will be invalid, we set the value to ""
                        if(map.containsKey(key)){
                            if(!map.get(key).equals(str)){
                                map.put(key, "");
                            }
                        }
                        else{
                            map.put(key, str);
                        }
                    }
                }
    
                public boolean isUnique(String word) {
                    return !map.containsKey(getKey(word))||map.get(getKey(word)).equals(word);
                }
    
                String getKey(String str){
                    if(str.length()<=2) return str;
                    return str.charAt(0)+Integer.toString(str.length()-2)+str.charAt(str.length()-1);
                }
            }
  • 相关阅读:
    mySQL安装的时候一直卡在starting server这里解决办法
    编译安装nginx
    用户访问网站原理及流程
    mysql备份及恢复
    sed
    mysql 基础
    nginx优化
    mysql 三种日志
    tr
    date
  • 原文地址:https://www.cnblogs.com/zmyvszk/p/5634928.html
Copyright © 2011-2022 走看看