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
25 changes: 25 additions & 0 deletions sik9252/BinarySearch.js
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;
};
28 changes: 28 additions & 0 deletions sik9252/FloodFill.js
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;
};
Copy link
Member

Choose a reason for hiding this comment

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

오 정석적인 BFS 풀이네요 👍
초기 예외 케이스 적용이나 변수처리가 깔끔해서
읽기 좋은 거 같아요

10 changes: 10 additions & 0 deletions sik9252/InvertBinaryTree.js
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];
Copy link
Collaborator

Choose a reason for hiding this comment

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

와 진짜 똑똑하시군요!

Copy link
Member

Choose a reason for hiding this comment

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

요론 방법이 👍


invertTree(root.left);
invertTree(root.right);
Comment on lines +6 to +7
Copy link
Collaborator

Choose a reason for hiding this comment

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

바로 넣을 생각을 못했네요!


return root;
};
16 changes: 16 additions & 0 deletions sik9252/ValidAnagram.js
Copy link
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,16 @@
var isAnagram = function (s, t) {
if (s.length !== t.length) return false;

const map = new Map();
Copy link
Member

Choose a reason for hiding this comment

The 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;
};