-
Notifications
You must be signed in to change notification settings - Fork 1
[WEEK05-2] 추슬기 #21
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
[WEEK05-2] 추슬기 #21
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,23 @@ | ||
| /** | ||
| * @param {string} a | ||
| * @param {string} b | ||
| * @return {string} | ||
| */ | ||
| var addBinary = function(a, b) { | ||
| let i = a.length - 1; | ||
| let j = b.length - 1; | ||
| let carry = 0; | ||
| let result = ""; | ||
|
|
||
| while (i >= 0 || j >= 0 || carry) { | ||
| let sum = carry; | ||
|
|
||
| if (i >= 0) sum += Number(a[i--]); | ||
| if (j >= 0) sum += Number(b[j--]); | ||
|
|
||
| result = String(sum % 2) + result; | ||
| carry = Math.floor(sum / 2); | ||
| } | ||
|
|
||
| return result; | ||
| }; |
|
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. Diameter of Binary Tree도 DFS로 높이를 구하면서 diameter를 갱신하는 전형적인 O(n) 풀이로 잘 작성해주신 것 같아요. 기능적으로는 큰 수정 포인트는 없어 보이고, 전반적으로 코드가 간결해서 읽기 좋았습니다! |
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,29 @@ | ||
| /** | ||
| * Definition for a binary tree node. | ||
| * function TreeNode(val, left, right) { | ||
| * this.val = (val===undefined ? 0 : val) | ||
| * this.left = (left===undefined ? null : left) | ||
| * this.right = (right===undefined ? null : right) | ||
| * } | ||
| */ | ||
| /** | ||
| * @param {TreeNode} root | ||
| * @return {number} | ||
| */ | ||
| var diameterOfBinaryTree = function(root) { | ||
| let diameter = 0; | ||
|
|
||
| function dfs(node) { | ||
| if (node === null) return 0; | ||
|
|
||
| const left = dfs(node.left); | ||
| const right = dfs(node.right); | ||
|
|
||
| diameter = Math.max(diameter, left + right); | ||
|
|
||
| return Math.max(left, right) + 1; | ||
| } | ||
|
|
||
| dfs(root); | ||
| return diameter; | ||
| }; |
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.
저도 처음에 푸신거처럼 parseInt로 했었는데 길이의 한계가 있다해서 찾아보니까 BigInt로 변환하면 된다고 하드라구용 근데 실전에서 이렇게 풀어도 되려나 싶긴하네요ㅠ 그래도 일단 테스트 통과하는게 우선이니