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

字符串字符匹配

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str1 = sc.next();
            String str2 = sc.next();
            boolean res = getRes(str1,str2);
            System.out.println(res);
        }
    }

    private static boolean getRes(String str1, String str2) {
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < str2.length(); i++) {
            set.add(str2.charAt(i));
        }
        int n1 = set.size();
        for (int i = 0; i < str1.length(); i++) {
            set.add(str1.charAt(i));
        }
        int n2 = set.size();
        if(n1 == n2){
            return true;
        }else{
            return false;
        }
    }
}
全部评论

相关推荐

迷茫的大四🐶:都收获五个了,兄弟那还说啥,不用改了,去玩吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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