字符串匹配
字符串匹配
http://www.nowcoder.com/questionTerminal/22fdeb9610ef426f9505e3ab60164c93
Set 轻松解决
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);
}
}
}
基恩士成长空间 452人发布