题解 | #字符串字符匹配#

字符串字符匹配

https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93

import java.util.*;
//一看是想复杂了以为要精准匹配子串用dp整了半天,结果只要都出现就可以,审题重要
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int max=Integer.MIN_VALUE;
        // 注意 hasNext 和 hasNextLine 的区别
        char[] str1 = in.nextLine().toCharArray();
        char[] str2 = in.nextLine().toCharArray();
        TreeMap<Character,Integer>vals=new TreeMap<Character,Integer>() {
        };
        for (int i = 0; i < str2.length; i++) {
            vals.put(str2[i],1);
        }
        for (int i = 0; i < str1.length; i++) {
            if(vals.get(str1[i])==null){
                System.out.println(false);
                return;
            }
        }
        System.out.println(true);

    }

}

华为OD机试 文章被收录于专栏

自己在准备机试,记录一下学习轨迹,主要参考真题,代码大部分是自己想的,不保证ac,仅供参考

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务