Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/com/school/faang/hashmap/задача_1/Solution.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
package com.school.faang.hashmap.задача_1;

import java.util.HashMap;

public class Solution {
public static void main(String[] args) {
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")); // комментарий
}
}