要求检查2个字符串,s1是否完全包含s2的字符集

package demo;

import java.util.HashMap;
import java.util.Map;

public class P74 {
//要求检查2个字符串,s1是否完全包含s2的字符集
	public static void main(String[] args) {
		String s1="abbbcdk";
		String s2="adhik";
		System.out.println(checkStr(s1,s2));
	}

	static boolean checkStr(String s1, String s2) {
		Map<Character, Integer> map=new HashMap<>();
		char temp;
		for(int i=0;i<s1.length();i++) {
			temp=s1.charAt(i);
			if(map.get(temp)==null)
				map.put(temp, 1);
		}
		for(int i=0;i<s2.length();i++) {
			temp=s2.charAt(i);
			if(map.get(temp)==null)
				return false;
		}
		
		return true;
	}
}
posted @ 2022-05-04 19:56  fighterk  阅读(38)  评论(0)    收藏  举报