From 3d771bbabeaf460f32a27d651faa740f6d9e1faa Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Fri, 16 Oct 2026 18:09:50 +0900 Subject: [PATCH 1/2] 4070. Minimum Rotations to Dial a Number I --- ...Minimum Rotations to Dial a Number I.java" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/4070. Minimum Rotations to Dial a Number I.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/4070. Minimum Rotations to Dial a Number I.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/4070. Minimum Rotations to Dial a Number I.java" new file mode 100644 index 00000000..f362fdc5 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/4070. Minimum Rotations to Dial a Number I.java" @@ -0,0 +1,36 @@ +/* + +1. 아이디어 : 다이얼 크기 10 -> 시계방향, 반시계방향 회전의 경우중 더 짧은것 선택 + + 경우의 수 (a->b) + 1. |a-b| + 2. 9 - |a-b| + +2. 시간복잡도 : O(s 문자열 길이) + +3. 자료구조/알고리즘 : 그리디 + + */ + +class Solution { + public int minRotations(String s) { + + int ans = 0; + int pos = 0; + + for(int i=0; i Date: Sat, 17 Oct 2026 23:44:21 +0900 Subject: [PATCH 2/2] 1311. Get Watched Videos by Your Friends --- .... Get Watched Videos by Your Friends.java" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/1311. Get Watched Videos by Your Friends.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/1311. Get Watched Videos by Your Friends.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/1311. Get Watched Videos by Your Friends.java" new file mode 100644 index 00000000..3be2a238 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/1311. Get Watched Videos by Your Friends.java" @@ -0,0 +1,87 @@ +/* +1. 아이디어: + - 그래프 구조에서 특정 노드 기준 거리가 k인 노드들을 체크 + - 그 노드들의 비디오 자료를 확인 후 커스텀 정렬 (1. 빈도수 2. 알파벳) + - 비디오 제목은 가짓수가 26^8이므로 hashmap 자료구조 사용 + - 또한 friends가 이미 그래프 구조이므로 별도 그래프 구조체를 만들지 않음 + +2. 시간복잡도: O(N + E + U log U) (N: 친구 수, E: 친구 관계 수, U: 고유 비디오 수) + +3. 자료구조/알고리즘: BFS + 커스텀 정렬 + HashMap +*/ +class Solution { + + private class Info { + String title; + int cnt; + + public Info (String title, int cnt) { + this.title = title; + this.cnt = cnt; + } + }; + + public List watchedVideosByFriends(List> watchedVideos, int[][] friends, int id, int level) { + + List friend = bfs(friends, id, level); + + Map map = new HashMap<>(); + + // 비디오 계산 + for(int i : friend) { + for(String video : watchedVideos.get(i)) { + if(!map.containsKey(video)) map.put(video, 1); + else map.put(video,map.get(video)+1); + } + } + + List info = new ArrayList<>(); + + // 구조체 삽입 + for(String key : map.keySet()) { + info.add(new Info(key, map.get(key))); + } + + Collections.sort(info, (a,b) ->{ + if(a.cnt == b.cnt) return a.title.compareTo(b.title); + return a.cnt - b.cnt; + }); + + List ans = new ArrayList<>(); + + for(Info i : info) { + ans.add(i.title); + } + + return ans; + } + + private List bfs(int[][] friends, int id, int level){ + Deque dq= new ArrayDeque<>(); + boolean[] visited= new boolean[friends.length]; + + List friend = new ArrayList<>(); + + dq.add(new int[]{id, 0}); + visited[id] = true; + + while(!dq.isEmpty()) { + int curr[] = dq.poll(); + + int currId = curr[0]; + int depth = curr[1]; + + if(depth == level) friend.add(currId); + + for(int next : friends[currId]) { + + if(visited[next] || depth>level) continue; + + dq.add(new int[]{next,depth+1}); + visited[next] = true; + } + } + + return friend; + } +} \ No newline at end of file