题解 | 字符串字符匹配

import java.util.Scanner;
import java.util.HashSet;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        HashSet<Character> set = new HashSet<>();
        for (int i = 0; i < str.length(); i++) {
            set.add(str.charAt(i));
        }
        String str1 = sc.nextLine();
        HashSet<Character> set1 = new HashSet<>();
        for (int i = 0; i < str1.length(); i++) {
            set1.add(str1.charAt(i));
        }
        int count = 0;
        for (Character c : set) {
            if (set1.contains(c)) {
                count++;
            }
        }
        if (count == set.size()) {
            System.out.println(true);
        } else {
            System.out.println(false);
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 14:32
点赞 评论 收藏
分享
牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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