zoukankan      html  css  js  c++  java
  • 890. 查找和替换模式

    890. 查找和替换模式
    https://leetcode-cn.com/contest/weekly-contest-98/problems/find-and-replace-pattern/
    package com.test;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    //https://leetcode-cn.com/contest/weekly-contest-98/problems/find-and-replace-pattern/
    //890. 查找和替换模式
    public class Lesson890 {
        public static void main(String[] args) {
            String[] words = {"abc","deq","mee","aqq","dkd","ccc"};
            String pattern = "abb";
            List<String> res = findAndReplacePattern(words, pattern);
            System.out.println(res);
        }
        public static List<String> findAndReplacePattern(String[] words, String pattern) {
            List<String> list = new ArrayList<>(8);
            String ptn = getPattern(pattern);
            System.out.println(ptn);
            for(int i=0;i<words.length;i++) {
                String word = words[i];
                String pattern1 = getPattern(word);
                if (ptn.equals(pattern1)) {
                    list.add(word);
                }
            }
            return list;
        }
    
        private static String getPattern(String pattern) {
            String ptn = "";
            Map<String, Integer> map = new HashMap<>(32);
            for(int i=0;i<pattern.length();i++) {
                String substring = pattern.substring(i, i + 1);
                Integer integer = map.get(substring);
                if (integer == null) {
                    int size = map.size();
                    map.put(substring, size + 1);
                }
                Integer integer_2 = map.get(substring);
                ptn = ptn+integer_2;
            }
            return ptn;
        }
    }
  • 相关阅读:
    NW.js开发环境的搭建
    EXPORTS与MODULE.EXPORTS的区别
    搭建 webpack + React 开发环境
    require,import区别?
    数据库中图片的二进制存储和显示
    二进制图片存储问题
    单线程(Thread)与多线程的区别
    软件测试心得--悲催我
    2015年-年度总结
    人生当中第一次转正
  • 原文地址:https://www.cnblogs.com/stono/p/9501191.html
Copyright © 2011-2022 走看看