Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
37 lines (34 loc) · 1.1 KB

File metadata and controls

37 lines (34 loc) · 1.1 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package leetcode;
import java.util.HashMap;
import java.util.Map;
public class leetcode1160 {
public int countCharacters(String[] words, String chars) {
int res=0;
Map<Character,Integer> own=new HashMap<>();
for (Character c:
chars.toCharArray()) {
own.put(c,own.getOrDefault(c,0)+1);
}
for (int i = 0; i <words.length ; i++) {
char [] temp=words[i].toCharArray();
Map<Character,Integer> tempmap=new HashMap<>();
boolean ismatch=true;
for (char c:
temp) {
tempmap.put(c,tempmap.getOrDefault(c,0)+1);
if (own.getOrDefault(c,0)==0||tempmap.get(c)>own.get(c)){ //字符表么没有或者少于
ismatch=false;
}
}
if (ismatch){
res+=words[i].length();
}
}
return res;
}
public static void main(String[] args) {
new leetcode1160().countCharacters(new String[]{
"hello","world","leetcode"
},"welldonehoneyr");
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.