-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckMagazine.java
More file actions
41 lines (28 loc) · 1014 Bytes
/
CheckMagazine.java
File metadata and controls
41 lines (28 loc) · 1014 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
package com.company;
import java.util.*;
public class Main {
public static void main(String[] args) {
String[] magazine = {"give", "me", "one", "grand", "today", "night"};
String[] note = {"give", "one", "grand", "today"};
checkMagazine(magazine, note);
}
static void checkMagazine(String[] magazine, String[] note) {
HashMap<String, Integer> magazineHash = new HashMap<>();
for (String word : magazine) {
if (magazineHash.containsKey(word)) {
magazineHash.put(word, magazineHash.get(word) + 1);
} else {
magazineHash.put(word, 1);
}
}
for (String word : note) {
if (magazineHash.containsKey(word) && magazineHash.get(word) > 0) {
magazineHash.put(word, magazineHash.get(word) - 1);
} else {
System.out.println("No");
return;
}
}
System.out.println("Yes");
}
}