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

字符串字符匹配

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String nextLine1 = scanner.nextLine();
        String s1 = replaceRepeat(nextLine1);
        String nextLine2 = scanner.nextLine();
        String s2 = replaceRepeat(nextLine2);
        for (int i = 0; i < s1.length(); i++) {
            if (!s2.contains(s1.charAt(i) + "")) {
                System.out.println("false");
                return;
            }
        }
        System.out.println("true");

    }

    private static String replaceRepeat(String nextLine) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < nextLine.length(); i++) {
            if (!str.toString().contains(nextLine.charAt(i) + "")) {
                str.append(nextLine.charAt(i));
            }
        }
        return str.toString();
    }
}
全部评论

相关推荐

舂锋:不能投什么岗都用一份简历,一般都是要看企业的岗位需求来写职业技能或者是项目经历,跟岗位相关的就写多一点。
点赞 评论 收藏
分享
码农索隆:有点耳熟,你们是我教过最差的一届
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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