题解 | #字符串字符匹配#
字符串字符匹配
http://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93
不理解。。改了几次都跟题解第一个几乎一样了 还是运行不了
import java.util.*;
public class Main {
public Main() {
}
public boolean isAllCharExist(String pShortString, String pLongString) {
Set<Character> set = new HashSet<>();
for (char ch : pLongString.toCharArray()) {
set.add(ch);
}
for (char ch : pShortString.toCharArray()) {
if (!set.contains(ch)) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Main solution = new Main();
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
String pShortString = in.nextLine();
String pLongString = in.nextLine();
boolean res = solution.isAllCharExist(pShortString, pLongString);
System.out.println(res);
}
}
}
// import java.util.*;
// public class Main{
// public static void main(String[] args){
// Scanner sc = new Scanner(System.in);
// while (sc.hasNextLine()) {
// String d = sc.nextLine();
// String l = sc.nextLine();
// boolean ok = ok(d, l);
// System.out.println(ok);
// }
// }
// public static boolean ok(String d,String l){
// Set<Character> hashSet = new HashSet();
// for (char c : d.toCharArray()) {
// hashSet.add(c);
// }
// for (char c2 : l.toCharArray()) {
// if (!hashSet.contains(c2)) {
// return false;
// }
// }
// return true;
// }
// }