forked from FAANG-School/hashmap_intensive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
39 lines (33 loc) · 1.05 KB
/
Copy pathSolution.java
File metadata and controls
39 lines (33 loc) · 1.05 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
package com.school.faang.hashmap.задача_1;
import java.util.HashMap;
public class Solution {
private HashMap<String, Integer> likesMap;
public Solution() {
likesMap = new HashMap<>();
}
public void likeVideo(String videoId) {
if (!likesMap.containsKey(videoId)) {
likesMap.put(videoId, 1);
}
else {
likesMap.put(videoId, likesMap.get(videoId) + 1);
}
}
public int getLikes(String videoId) {
if (likesMap.containsKey(videoId)) {
return likesMap.get(videoId);
}
else {
return 0;
}
}
public static void main(String[] args) {
Solution solution = new Solution();
solution.likeVideo("dQw4w9WgXcQ");
solution.likeVideo("dQw4w9WgXcQ");
solution.likeVideo("asd32adS");
System.out.println(solution.getLikes("dQw4w9WgXcQ"));
System.out.println(solution.getLikes("asd32adS"));
System.out.println(solution.getLikes("daqeqw2sa3AS")); // комментарий
}
}