-
-
Notifications
You must be signed in to change notification settings - Fork 245
[jun0811] WEEK 06 solutions #1868
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,24 @@ | ||
/** | ||
* @param {number[]} height | ||
* @return {number} | ||
*/ | ||
var maxArea = function (height) { | ||
// 더 낮은 쪽을 안쪽으로 이동하는 방식으로 | ||
|
||
let start = 0; | ||
let end = height.length - 1; | ||
let res = -1; | ||
while (start <= end) { | ||
const v = Math.min(height[start], height[end]) * (end - start); | ||
if (v > res) { | ||
res = v; | ||
} | ||
|
||
if (height[start] > height[end]) { | ||
end -= 1; | ||
} else { | ||
start += 1; | ||
} | ||
} | ||
return res; | ||
}; |
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,65 @@ | ||
var WordDictionary = function () { | ||
this.trie = {}; // Trie 루트 노드 | ||
}; | ||
|
||
/** | ||
* @param {string} word | ||
* @return {void} | ||
*/ | ||
WordDictionary.prototype.addWord = function (word) { | ||
let current = this.trie; | ||
|
||
// 각 문자마다 노드 생성 | ||
for (let i = 0; i < word.length; i++) { | ||
const char = word[i]; | ||
if (!current[char]) { | ||
current[char] = {}; | ||
} | ||
current = current[char]; | ||
} | ||
|
||
// 단어의 끝 표시 | ||
current.isEnd = true; | ||
}; | ||
|
||
/** | ||
* @param {string} word | ||
* @return {boolean} | ||
*/ | ||
WordDictionary.prototype.search = function (word) { | ||
return dfs(word, 0, this.trie); | ||
}; | ||
|
||
/** | ||
* @param {string} word - 검색할 단어 | ||
* @param {number} index - 현재 검사 중인 문자 인덱스 | ||
* @param {object} node - 현재 Trie 노드 | ||
* @return {boolean} | ||
*/ | ||
function dfs(word, index, node) { | ||
// 단어 끝에 도달했으면 isEnd 확인 | ||
if (index === word.length) { | ||
return !!node.isEnd; | ||
} | ||
|
||
const char = word[index]; | ||
|
||
if (char === '.') { | ||
// '.'인 경우: 모든 자식 노드를 탐색 | ||
for (let key in node) { | ||
if (key !== 'isEnd') { | ||
// isEnd 속성은 제외 | ||
if (dfs(word, index + 1, node[key])) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} else { | ||
// 일반 문자인 경우: 해당 문자의 노드로 이동 | ||
if (!node[char]) { | ||
return false; | ||
} | ||
return dfs(word, index + 1, node[char]); | ||
} | ||
} |
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,22 @@ | ||
/** | ||
* @param {string} s | ||
* @return {boolean} | ||
*/ | ||
var isValid = function (s) { | ||
const match = { | ||
')': '(', | ||
']': '[', | ||
'}': '{', | ||
}; | ||
if (match[s[0]]) return false; | ||
const stack = []; | ||
for (const bracket of s) { | ||
if (bracket == '(' || bracket == '{' || bracket == '[') stack.push(bracket); | ||
else { | ||
const openBracket = stack.pop(); | ||
if (match[bracket] != openBracket) return false; | ||
} | ||
} | ||
if (stack.length > 0) return false; | ||
return true; | ||
}; |
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.
Uh oh!
There was an error while loading. Please reload this page.