-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRansomNote.java
More file actions
55 lines (44 loc) · 1.36 KB
/
RansomNote.java
File metadata and controls
55 lines (44 loc) · 1.36 KB
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
47
48
49
50
51
52
53
54
55
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
// Complete the checkMagazine function below.
static String checkMagazine(String[] magazine, String[] note) {
HashMap<String,Integer> hm = new HashMap<String,Integer>();
for(String s : magazine){
if(!hm.containsKey(s))
hm.put(s,1);
else
hm.put(s, hm.get(s)+1);
}
for(String s : note){
if(!hm.containsKey(s) || hm.get(s) <= 0)
return "No";
else
hm.put(s, hm.get(s)-1);
}
return "Yes";
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int m = scanner.nextInt();
int n = scanner.nextInt();
scanner.nextLine();
if(n > m)
System.out.println("No");
else{
String[] mag = new String[m];
String[] note = new String[n];
String mS = scanner.nextLine();
String nS = scanner.nextLine();
mag = mS.split(" ");
note = nS.split(" ");
System.out.println(checkMagazine(mag,note));
}
scanner.close();
}
}