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
22 changes: 22 additions & 0 deletions container-with-most-water/Cyjin-jani.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers
  • 설명: 이 코드는 양 끝에서 시작하여 포인터를 이동시키는 방식으로 최대 면적을 찾는 두 포인터 패턴을 사용합니다. 효율적인 탐색을 위해 양쪽 포인터를 조절하며 조건에 따라 이동합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// tc: O(n);
// sc: O(1);
const maxArea = function (height) {
let max = 0;
let leftIdx = 0;
let rightIdx = height.length - 1;

while (leftIdx < rightIdx) {
const width = rightIdx - leftIdx;
const minHeight = Math.min(height[leftIdx], height[rightIdx]);
const area = width * minHeight;
max = Math.max(max, area);

if (height[leftIdx] > height[rightIdx]) {
rightIdx -= 1;
} else {
leftIdx += 1;
}
}

return max;
};
47 changes: 47 additions & 0 deletions design-add-and-search-words-data-structure/Cyjin-jani.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set
  • 설명: 이 코드는 단어 저장을 위해 Set을 사용하며, 검색 시 문자열 비교를 통해 일치 여부를 판단하는 구조로 해시 자료구조를 활용합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var WordDictionary = function () {
this.dictionary = new Set();
};

/**
* @param {string} word
* @return {void}
*/
WordDictionary.prototype.addWord = function (word) {
this.dictionary.add(word);
};

/**
* @param {string} word
* @return {boolean}
*/

// tc: O(n * k), n: dictionary size, k: word length => O(n) in worst case
// sc: O(1)
WordDictionary.prototype.search = function (word) {
if (!word.includes('.')) {
return this.dictionary.has(word);
}

for (const stored of this.dictionary) {
if (stored.length !== word.length) continue;

let isMatch = true;
for (let i = 0; i < word.length; i++) {
if (word[i] === '.') continue;
if (word[i] !== stored[i]) {
isMatch = false;
break;
}
}
if (isMatch) return true;
}

return false;
};

/**
* Your WordDictionary object will be instantiated and called as such:
* var obj = new WordDictionary()
* obj.addWord(word)
* var param_2 = obj.search(word)
*/
34 changes: 34 additions & 0 deletions valid-parentheses/Cyjin-jani.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Stack / Priority Queue
  • 설명: 이 코드는 괄호의 유효성을 검사하기 위해 스택 자료구조를 사용하여 열린 괄호와 닫힌 괄호를 매칭하는 방식을 활용합니다. 스택은 괄호의 짝을 맞추는 데 적합한 구조입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// tc: O(n)
// sc: O(n)
const isValid = function (s) {
const bracketMap = {
'(': ')',
'{': '}',
'[': ']',
};

if (s.length % 2 !== 0 || isCloseBracket(s[0])) return false;

const stack = [];

for (let i = 0; i < s.length; i++) {
if (stack.length === 0) {
stack.push(s[i]);
continue;
}

let topBracket = stack.pop();
if (bracketMap[topBracket] !== s[i]) {
stack.push(topBracket);
stack.push(s[i]);
}
}

return stack.length === 0;
};

function isCloseBracket(char) {
const closeBrackets = [')', '}', ']'];

return closeBrackets.includes(char);
}
Loading