-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode1832_SentencePanagram.java
More file actions
59 lines (51 loc) · 1.5 KB
/
Copy pathleetcode1832_SentencePanagram.java
File metadata and controls
59 lines (51 loc) · 1.5 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
56
57
58
59
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class leetcode1832_SentencePanagram {
public static boolean checkIfPangram(String sentence) {
HashMap<Character, Integer> map = new HashMap<>();
map.put('a', 0);
map.put('b', 0);
map.put('c', 0);
map.put('d', 0);
map.put('e', 0);
map.put('f', 0);
map.put('g', 0);
map.put('h', 0);
map.put('i', 0);
map.put('j', 0);
map.put('k', 0);
map.put('l', 0);
map.put('m', 0);
map.put('n', 0);
map.put('o', 0);
map.put('p', 0);
map.put('q', 0);
map.put('r', 0);
map.put('s', 0);
map.put('t', 0);
map.put('u', 0);
map.put('v', 0);
map.put('w', 0);
map.put('x', 0);
map.put('y', 0);
map.put('z', 0);
for (int i = 0; i < sentence.length(); i++) {
map.put(sentence.charAt(i), map.get(sentence.charAt(i)) + 1);
}
int val;
// Getting an iterator
Iterator iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry key = (Map.Entry) iterator.next();
val = ((int) key.getValue());
if (val == 0)
return false;
}
return true;
}
public static void main(String[] args) {
String sentence = "thequickbrownfoxjumpsoverthelazydog";
boolean res = checkIfPangram(sentence);
}
}