-
Notifications
You must be signed in to change notification settings - Fork 1
[WEEK02] 이지현 #4
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
[WEEK02] 이지현 #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * @param {number[]} nums | ||
| * @param {number} target | ||
| * @return {number} | ||
| */ | ||
| var search = function (nums, target) { | ||
| let left = 0; | ||
| let right = nums.length - 1; | ||
|
|
||
| while (left <= right) { | ||
| const mid = Math.floor((left + right) / 2); | ||
|
|
||
| if (nums[mid] === target) { | ||
| return mid; | ||
| } | ||
|
|
||
| if (nums[mid] < target) { | ||
| left = mid + 1; | ||
| } else { | ||
| right = mid - 1; | ||
| } | ||
| } | ||
|
|
||
| return -1; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| var floodFill = function (image, sr, sc, color) { | ||
| const startColor = image[sr][sc]; | ||
| if (startColor === color) return image; | ||
|
|
||
| const dx = [-1, 1, 0, 0]; | ||
| const dy = [0, 0, -1, 1]; | ||
| const row = image.length; | ||
| const col = image[0].length; | ||
|
|
||
| const queue = [[sr, sc]]; | ||
| image[sr][sc] = color; | ||
|
|
||
| while (queue.length) { | ||
| const [x, y] = queue.shift(); | ||
|
|
||
| for (let i = 0; i < 4; i++) { | ||
| const nx = x + dx[i]; | ||
| const ny = y + dy[i]; | ||
|
|
||
| if (nx >= 0 && nx < row && ny >= 0 && ny < col && image[nx][ny] === startColor) { | ||
| image[nx][ny] = color; | ||
| queue.push([nx, ny]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return image; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| var invertTree = function (root) { | ||
| if (root === null) return null; | ||
|
|
||
| [root.left, root.right] = [root.right, root.left]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와 진짜 똑똑하시군요!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요론 방법이 👍 |
||
|
|
||
| invertTree(root.left); | ||
| invertTree(root.right); | ||
|
Comment on lines
+6
to
+7
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 바로 넣을 생각을 못했네요! |
||
|
|
||
| return root; | ||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 매우 풀이가 깔끔하네요 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| var isAnagram = function (s, t) { | ||
| if (s.length !== t.length) return false; | ||
|
|
||
| const map = new Map(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s, t 각각 Map을 사용했었는데 하나로 해도좋은 거 같아요! 👍 💯 |
||
|
|
||
| for (let i = 0; i < s.length; i++) { | ||
| map.set(s[i], (map.get(s[i]) || 0) + 1); | ||
| map.set(t[i], (map.get(t[i]) || 0) - 1); | ||
| } | ||
|
|
||
| for (const value of map.values()) { | ||
| if (value !== 0) return false; | ||
| } | ||
|
|
||
| return true; | ||
| }; | ||
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.
오 정석적인 BFS 풀이네요 👍
초기 예외 케이스 적용이나 변수처리가 깔끔해서
읽기 좋은 거 같아요