-
-
Notifications
You must be signed in to change notification settings - Fork 195
[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
Changes from all commits
Commits
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,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])); |
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,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) | ||
*/ |
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,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; | ||
}; |
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.
문제에서 class로 구현하라고 되어 있었는데, 함수 생성자 패턴으로 풀어주셨네요!
혹시 이렇게 작성하신 특별한 이유가 있을까요?
class를 사용하면 코드 가독성이나 현대 JS 문법 흐름에도 더 맞을 것 같아서요. 😊
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.
아 풀이할때 리트코드 기본세팅이 var로되어잇어서 바꿀생각을 못햇네요!
피드백 감사합니다.