-
Notifications
You must be signed in to change notification settings - Fork 4
[oh-chaeyeon] 25.02.20 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
2c03149
배열 자르기 / 기초
oh-chaeyeon b307f95
배열 원소의 길이 / 기초
oh-chaeyeon 280b794
배열 회전시키기 / 기초
oh-chaeyeon 2465ff2
중복된 숫자 개수 / 기초
oh-chaeyeon 9b120c8
제일 작은 수 제거하기 / 중급
oh-chaeyeon e54d44a
행렬의 덧셈 / 중급
oh-chaeyeon 7f618bf
나누어 떨어지는 숫자 배열 / 중급
oh-chaeyeon 121d553
행렬의 곱셈 / 심화
oh-chaeyeon 1c9229c
교점에 별 만들기 / 심화
oh-chaeyeon 865c257
n^2 배열 자르기 / 심화
oh-chaeyeon ea88f07
String Reversal / 기초
oh-chaeyeon 3f26859
Control Z / 기초
oh-chaeyeon a8c82b3
Hate English / 기초
oh-chaeyeon 4a4f3f2
String Calculation / 기초
oh-chaeyeon d30a080
Crane Game / 중급
oh-chaeyeon a560deb
Valid Parentheses / 중급
oh-chaeyeon 7dadd5d
Dart Game / 중급
oh-chaeyeon b2fdfc6
Rotate Parentheses / 심화
oh-chaeyeon e00f4cd
Stock Price / 심화
oh-chaeyeon 9bd1415
Delivery Box / 심화
oh-chaeyeon 92aa4e2
Merge branch 'main' into ohchaeyeon
oh-chaeyeon 8b3840d
순서쌍의 개수 / 기초
oh-chaeyeon 071e7cc
점의 위치 구하기 / 기초
oh-chaeyeon 5b02168
로그인 성공? / 기초
oh-chaeyeon a358d28
특이한 정렬 / 기초
oh-chaeyeon d0819a1
카드 뭉치 / 중급
oh-chaeyeon 420da51
공원 산책 / 중급
oh-chaeyeon f4bc768
햄버거 만들기 / 중급
oh-chaeyeon c6c4400
Merge branch 'main' into ohchaeyeon
oh-chaeyeon 5815b69
모스부호1 / 기초
oh-chaeyeon 474e842
A로 B만들기 / 기초
oh-chaeyeon c726708
진로 순서 정하기 / 기초
oh-chaeyeon e30e7d6
등수 매기기 / 기초
oh-chaeyeon a8d94b1
완주하지 못한 선수 / 중급
oh-chaeyeon e27c3a9
포켓몬 / 중급
oh-chaeyeon d2301ff
추억 점수 / 중급
oh-chaeyeon 16b93e3
할인 행사 / 심화
oh-chaeyeon 4b3f8ee
오픈채팅방 / 심화
oh-chaeyeon 947ecc7
Merge branch 'main' into ohchaeyeon
oh-chaeyeon e4cfdac
Merge branch 'main' into ohchaeyeon
oh-chaeyeon eba0569
Maximum Depth of Binary Tree / 초급
oh-chaeyeon d4d1840
Binary Tree Inorder Traversal / 초급
oh-chaeyeon 1602133
Same Tree / 초급
oh-chaeyeon 648f832
Invert Binary Tree / 초급
oh-chaeyeon 94cfe6d
Binary Tree Level Order Traversal / 중급
oh-chaeyeon 98fa450
Validate Binary Search Tree / 중급
oh-chaeyeon c2ef4b3
Construct Binary Tree from Preorder and Inorder Traversal / 중급
oh-chaeyeon 8228c60
이진 변환 반복하기 / 심화
oh-chaeyeon de828da
Binary Tree Maximum Path Sum / 심화
oh-chaeyeon 3014876
Merge branch 'main' into ohchaeyeon
oh-chaeyeon 7817495
Find the Town Judge / 기초
oh-chaeyeon 8dcfb92
Find if Path Exists in Graph / 기초
oh-chaeyeon 4cf5fdf
Find Center of Star Graph / 기초
oh-chaeyeon 9f47b9b
게임 맵 최단거리 / 중급
oh-chaeyeon ddfb81f
타겟 넘버 / 중급
oh-chaeyeon 0016a9a
전력망을 둘로 나누기 / 심화
oh-chaeyeon 4e37e37
배달 / 심화
oh-chaeyeon f60c8eb
Merge branch 'main' into ohchaeyeon
oh-chaeyeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * @param {number[][]} edges | ||
| * @return {number} | ||
| */ | ||
| var findCenter = function (edges) { | ||
| return edges[0][0] === edges[1][0] || edges[0][0] === edges[1][1] | ||
| ? edges[0][0] | ||
| : edges[0][1]; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * @param {number} n | ||
| * @param {number[][]} edges | ||
| * @param {number} source | ||
| * @param {number} destination | ||
| * @return {boolean} | ||
| */ | ||
| var validPath = function (n, edges, source, destination) { | ||
| const graph = Array.from({ length: n }, () => []); | ||
|
|
||
| edges.forEach(([u, v]) => { | ||
| graph[u].push(v); | ||
| graph[v].push(u); | ||
| }); | ||
|
|
||
| const visited = new Set(); | ||
|
|
||
| const dfs = (node) => { | ||
| if (node === destination) return true; | ||
| visited.add(node); | ||
|
|
||
| for (const neighbor of graph[node]) { | ||
| if (!visited.has(neighbor) && dfs(neighbor)) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| }; | ||
|
|
||
| return dfs(source); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * @param {number} n | ||
| * @param {number[][]} trust | ||
| * @return {number} | ||
| */ | ||
| var findJudge = function (n, trust) { | ||
| const trustCount = new Array(n + 1).fill(0); | ||
|
|
||
| for (const [a, b] of trust) { | ||
| trustCount[a]--; | ||
| trustCount[b]++; | ||
| } | ||
|
|
||
| for (let i = 1; i <= n; i++) { | ||
| if (trustCount[i] === n - 1) { | ||
| return i; | ||
| } | ||
| } | ||
|
|
||
| return -1; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| function solution(maps) { | ||
| const n = maps.length; | ||
| const m = maps[0].length; | ||
| const directions = [ | ||
| [1, 0], | ||
| [-1, 0], | ||
| [0, 1], | ||
| [0, -1], | ||
| ]; | ||
| const queue = [[0, 0]]; | ||
| const visited = Array.from({ length: n }, () => Array(m).fill(false)); | ||
| visited[0][0] = true; | ||
| let count = 1; | ||
|
|
||
| while (queue.length > 0) { | ||
| const size = queue.length; | ||
| for (let i = 0; i < size; i++) { | ||
| const [x, y] = queue.shift(); | ||
|
|
||
| if (x === n - 1 && y === m - 1) { | ||
| return count; | ||
| } | ||
|
|
||
| for (const [dx, dy] of directions) { | ||
| const nx = x + dx; | ||
| const ny = y + dy; | ||
|
|
||
| if ( | ||
| nx >= 0 && | ||
| ny >= 0 && | ||
| nx < n && | ||
| ny < m && | ||
| maps[nx][ny] === 1 && | ||
| !visited[nx][ny] | ||
| ) { | ||
| visited[nx][ny] = true; | ||
| queue.push([nx, ny]); | ||
| } | ||
| } | ||
| } | ||
| count++; | ||
| } | ||
|
|
||
| return -1; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| function solution(N, road, K) { | ||
| const graph = Array.from({ length: N + 1 }, () => []); | ||
|
|
||
| for (const [a, b, c] of road) { | ||
| graph[a].push([b, c]); | ||
| graph[b].push([a, c]); | ||
| } | ||
|
|
||
| const distances = Array(N + 1).fill(Infinity); | ||
| distances[1] = 0; | ||
| const priorityQueue = [[0, 1]]; | ||
|
|
||
| while (priorityQueue.length > 0) { | ||
| const [currentDistance, currentNode] = priorityQueue.shift(); | ||
|
|
||
| if (currentDistance > distances[currentNode]) { | ||
| continue; | ||
| } | ||
|
|
||
| for (const [neighbor, time] of graph[currentNode]) { | ||
| const newDistance = currentDistance + time; | ||
| if (newDistance < distances[neighbor]) { | ||
| distances[neighbor] = newDistance; | ||
| priorityQueue.push([newDistance, neighbor]); | ||
| priorityQueue.sort((a, b) => a[0] - b[0]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return distances.filter((distance) => distance <= K).length; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| function solution(n, wires) { | ||
| const graph = Array.from({ length: n + 1 }, () => []); | ||
|
|
||
| for (const [v1, v2] of wires) { | ||
| graph[v1].push(v2); | ||
| graph[v2].push(v1); | ||
| } | ||
|
|
||
| let minDifference = Number.MAX_VALUE; | ||
|
|
||
| const dfs = (node, visited) => { | ||
| let count = 1; | ||
| visited[node] = true; | ||
|
|
||
| for (const neighbor of graph[node]) { | ||
| if (!visited[neighbor]) { | ||
| count += dfs(neighbor, visited); | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| }; | ||
|
|
||
| for (const [v1, v2] of wires) { | ||
| const visited = Array(n + 1).fill(false); | ||
| visited[v1] = true; | ||
| const count = dfs(v2, visited); | ||
| const difference = Math.abs(count - (n - count)); | ||
| minDifference = Math.min(minDifference, difference); | ||
| } | ||
|
|
||
| return minDifference; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| function solution(numbers, target) { | ||
| const dp = new Map(); | ||
| dp.set(0, 1); | ||
|
|
||
| for (const number of numbers) { | ||
| const nextDp = new Map(); | ||
| for (const [sum, count] of dp) { | ||
| nextDp.set(sum + number, (nextDp.get(sum + number) || 0) + count); | ||
| nextDp.set(sum - number, (nextDp.get(sum - number) || 0) + count); | ||
| } | ||
| dp.clear(); | ||
| for (const [sum, count] of nextDp) { | ||
| dp.set(sum, count); | ||
| } | ||
| } | ||
|
|
||
| return dp.get(target) || 0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
새 원소를 넣을때마다 sort를 진행하는 것 보다는 큐에서 원소를 꺼내기 전에 sort해주는게 더 효율적일 것 같습니다!