题解 | 字符串字符匹配

字符串字符匹配

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        HashSet<Character> st1 = new HashSet<>();
        HashSet<Character> st2 = new HashSet<>();
        String str1 = in.next();
        String str2 = in.next();
        for(char c : str1.toCharArray())st1.add(c);
        for(char c : str2.toCharArray())st2.add(c);
        System.out.print(st2.containsAll(st1));
    }
}

非常规整的解法

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-20 12:46
瘦嘟嘟右卫门:百度文库网盘的暑期也没约面吗
点赞 评论 收藏
分享
鲸鸿:实习协议不用管签多久,要走的时候提前三天说就可以了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务