-
Notifications
You must be signed in to change notification settings - Fork 1
[WEEK07-1] 이지현 #29
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
[WEEK07-1] 이지현 #29
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,27 @@ | ||
| /** | ||
| * @param {string} s | ||
| * @param {string} t | ||
| * @return {boolean} | ||
| */ | ||
| var backspaceCompare = function (s, t) { | ||
| const calcS = calc(s); | ||
| const calcT = calc(t); | ||
|
|
||
| return calcS === calcT; | ||
| }; | ||
|
|
||
| var calc = function (str) { | ||
| const stack = []; | ||
|
|
||
| for (let i = 0; i < str.length; i++) { | ||
| if (!stack.length && str[i] === "#") continue; | ||
|
|
||
| if (str[i] === "#") { | ||
| stack.pop(); | ||
| } else { | ||
| stack.push(str[i]); | ||
| } | ||
| } | ||
|
|
||
| return [...stack].join(""); | ||
| }; | ||
|
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,17 @@ | ||
| var countBits = function (n) { | ||
| const result = []; | ||
|
|
||
| for (let i = 0; i <= n; i++) { | ||
| let num = i; | ||
| let count = 0; | ||
|
|
||
| while (num > 0) { | ||
| num = num & (num - 1); | ||
|
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. 여기 부분이 어떻게 동작하는지 설명 부탁드려도 될까요?! |
||
| count++; | ||
| } | ||
|
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. 오 이렇게 푸는방법도 있네요!!! |
||
|
|
||
| result.push(count); | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
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.
stack이 배열인데 다시 배열에 넣어주고 있는 것 같아 보여요!