Skip to content
Open
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
24 changes: 24 additions & 0 deletions container-with-most-water/jun0811.js
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;
};
65 changes: 65 additions & 0 deletions design-add-and-search-words-data-structure/jun0811.js
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]);
}
}
22 changes: 22 additions & 0 deletions valid-parentheses/jun0811.js
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;
};