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

字符串字符匹配

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();
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 11:16
点赞 评论 收藏
分享
身边有人上海、深圳&nbsp;6、7k&nbsp;都去了,真就带薪上班了。
程序员小白条:木的办法, 以后越来越差,还是家附近宅着吧,毕业的人越来越多,岗位都提供不出来,经济又过了人口红利期
点赞 评论 收藏
分享
能干的三文鱼刷了10...:公司可能有弄嵌入式需要会画pcb的需求,而且pcb能快速直观看出一个人某方面的实力。看看是否有面试资格。问你问题也能ai出来,pcb这东西能作假概率不高
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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