Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions doitchuu/BackspaceStringCompare.js
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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,22 @@
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var backspaceCompare = function(s, t) {
return getRemainString(s) === getRemainString(t);
};

function getRemainString(str) {
const stack = [];

for (let i = 0; i < str.length; i++) {
if (str[i] === "#") {
stack.pop();
} else {
stack.push(str[i]);
}
}

return stack.join("");
}
18 changes: 18 additions & 0 deletions doitchuu/CountingBits.js
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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,18 @@
/**
* @param {number} n
* @return {number[]}
*/
var countBits = function(n) {
const dp = [0];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dp로 구현하진 못했지만 dp를 써야한다는 건 알았던 걸까요?!


if (n === 0) {
return dp;
}

for (let i = 1; i <= n; i++) {
const count = i.toString(2).replaceAll("0", "").length;
dp.push(count);
}

return dp;
};
15 changes: 15 additions & 0 deletions doitchuu/NumberOf1Bits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param {number} n - a positive integer
* @return {number}
*/
var hammingWeight = function(n) {
let current = n >>> 0;
let count = 0;

while (current !== 0) {
current &= current - 1;
count++;
}

return count;
};
28 changes: 28 additions & 0 deletions doitchuu/SameTree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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} p
* @param {TreeNode} q
* @return {boolean}
*/
var isSameTree = function(p, q) {
if (p === null && q === null) {
return true;
}

if (p === null || q === null) {
return false;
}

if (p.val !== q.val) {
return false;
}

return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
};