classSolution{publicbooleancanConstruct(String ransomNote,String magazine){Map<String,Integer> map =newHashMap<>();for(int i =0; i < magazine.length(); i++){String word =String.valueOf(magazine.charAt(i));
map.put(word, map.getOrDefault(word,0)+1);}for(int i =0; i < ransomNote.length(); i++){String word =String.valueOf(ransomNote.charAt(i));if(!map.containsKey(word)){returnfalse;}if(map.get(word)<1){returnfalse;}
map.put(word, map.getOrDefault(word,0)-1);}returntrue;}}
// 代码随想录提供的题解classSolution{publicbooleancanConstruct(String ransomNote,String magazine){if(ransomNote.length()> magazine.length()){returnfalse;}int[] judge =newint[26];for(char word : magazine.toCharArray()){
judge[word -'a']+=1;}for(char c : ransomNote.toCharArray()){
judge[c -'a']-=1;}for(int i : judge){if(i <=0){returnfalse;}}returntrue;}}
目录 【Python学习】Python学习8-Number 前言在变量赋值时被创建Python支持四种不同的数据类型整型(Int)长整型(long integers)浮点型(loating point real values)复数(complex numbers) Python Number 类型转换Python math 模块、cmath 模块Python数学函数Python随…