两串的字符集相同(开辟辅助空间)
/* s1=abcde
- s2=abcd
- return ture;
- 弊端:限制字符串的ASCII
*/
package _4字符串;
public class h两串的字符集相同 {
public static void main(String[] args) {
boolean res=check("abcdef","abcde");
System.out.println(res);
}
static boolean check(String s1,String s2) {
//扫描s1
int []help=new int[256];
for (int i = 0; i < s1.length(); i++) {
char c =s1.charAt(i);
if(help[c]==0) {
help[c]=1;
}
}
//扫描s2
for (int i = 0; i < s2.length(); i++) {
char c=s2.charAt(i);
if(help[c]==0) {
return false;
}
}
return true;
}
}