Skip to content

[moonjonghoo] Week 06 Solutions #1444

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 3 commits into from
May 9, 2025
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
26 changes: 26 additions & 0 deletions container-with-most-water/moonjonghoo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function (height) {
let max_area = 0;
let left = 0;
let right = height.length - 1;
while (left < right) {
let current_x = right - left;
let current_y = Math.min(height[left], height[right]);
let current_area = current_x * current_y;

if (current_area > max_area) {
max_area = current_area;
}
if (height[left] < height[right]) {
left = left + 1;
} else {
right = right - 1;
}
}
return max_area;
};

console.log(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7]));
36 changes: 36 additions & 0 deletions design-add-and-search-words-data-structure/moonjonghoo.js
Copy link
Contributor

Choose a reason for hiding this comment

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

문제에서 class로 구현하라고 되어 있었는데, 함수 생성자 패턴으로 풀어주셨네요!
혹시 이렇게 작성하신 특별한 이유가 있을까요?
class를 사용하면 코드 가독성이나 현대 JS 문법 흐름에도 더 맞을 것 같아서요. 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

아 풀이할때 리트코드 기본세팅이 var로되어잇어서 바꿀생각을 못햇네요!
피드백 감사합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const TrieNode = function () {
this.children = {};
this.isEndOfWord = false;
};
var WordDictionary = function () {
this.root = new TrieNode();
};

/**
* @param {string} word
* @return {void}
*/
WordDictionary.prototype.addWord = function (word) {
let currentNode = this.root;
for (let i = 0; i < word.length; i++) {
let char = word[i];
if (!currentNode.children[char]) {
currentNode.children[char] = new TrieNode();
}
currentNode = currentNode.children[char];
}
currentNode.isEndOfWord = true;
};

/**
* @param {string} word
* @return {boolean}
*/
WordDictionary.prototype.search = function (word) {};

/**
* Your WordDictionary object will be instantiated and called as such:
* var obj = new WordDictionary()
* obj.addWord(word)
* var param_2 = obj.search(word)
*/
18 changes: 18 additions & 0 deletions valid-parentheses/moonjonghoo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @param {string} s
* @return {boolean}
*/
var isValid = function (s) {
let object = { ")": "(", "}": "{", "]": "[" };
let stack = [];
for (let char of s) {
if (char === "(" || char === "{" || char === "[") {
stack.push(char);
} else {
if (stack.length === 0 || stack.pop() !== object[char]) {
return false;
}
}
}
return stack.length === 0;
};