-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamazingStrings.java
More file actions
46 lines (38 loc) · 895 Bytes
/
amazingStrings.java
File metadata and controls
46 lines (38 loc) · 895 Bytes
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
38
39
40
41
42
43
44
45
46
import java.util.HashMap;
public class Solution {
public static String amazingStrings(String first, String second,String third) {
// Write your code here.
HashMap<Character,Integer> map = new HashMap<>();
for(int i=0;i<first.length();i++){
char c = first.charAt(i);
if(map.containsKey(c)){
map.put(c, map.get(c) +1);
} else {
map.put(c, 1);
}
}
for(int i=0;i<second.length();i++){
char c = second.charAt(i);
if(map.containsKey(c)){
map.put(c, map.get(c) +1);
} else {
map.put(c, 1);
}
}
for(int i=0;i<third.length();i++){
char c = third.charAt(i);
if(!map.containsKey(c)){
return "NO";
}else {
map.put(c, map.get(c) - 1);
}
}
boolean allValuesAreZero = true;
for (Integer value : map.values()) {
if (value != 0) {
return "NO";
}
}
return "YES";
}
}