两串的字符集相同采用哈希方法
import java.util.HashMap;
import java.util.Map;
public class i两串的字符集相同哈希 {
public static void main(String[] args) {
boolean res=check("abcdef","abcde");
System.out.println(res);
}
private static boolean check(String s1, String s2) {
Map<Character,Integer>map=new HashMap<>();
for (int i = 0; i < s1.length(); i++) {
char c=s1.charAt(i);
if(map.get(c)==null) {
map.put(c,1);
}
}
for (int i = 0; i < s2.length(); i++) {
char c =s2.charAt(i);
if(map.get(c)==null) {
return false;
}
}
return true;
}
}