Skip to content
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

[호돌이] Week 6 #892

Merged
merged 3 commits into from
Jan 18, 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
24 changes: 24 additions & 0 deletions container-with-most-water/yeeZinu.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 max = 0; // 최대값
let left = 0; // 왼쪽 값
let right = height.length - 1; // 오른쪽 값

// 왼쪽과 오른쪽을 하나씩 줄여가며 가운데서 만날 때 까지 반복
while (left < right) {
// 최대값 = 가로길이(오른쪽 값 - 왼쪽 값) * 세로길이(왼쪽 값, 오른쪽 값 중 더 작은 값)
max = Math.max(max, (right - left) * Math.min(height[left], height[right]));
// 오른쪽 세로가 더 높다면 왼쪽 값 증가
if (height[left] < height[right]) {
left++;
}
else {
right--;
}
}
return max;
};
73 changes: 73 additions & 0 deletions design-add-and-search-words-data-structure/yeeZinu.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Node 라는 새로운 객체를 만드신 것과 활용이 잘 적용된 풀이 같아요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// node 함수선언
function Node() {
this.child = {};
this.end = false;
}

// 최상단의 루트를 노드로 초기화
var WordDictionary = function () {
this.root = new Node();
};

/**
* @param {string} word
* @return {void}
*/
WordDictionary.prototype.addWord = function (word) {
// 현재위치를 최상단으로 초기화
let current = this.root;

// 문자를 받고 단어하나씩 노드에 저장
for (const char of word) {
if (!current.child[char]) {
current.child[char] = new Node();
}
current = current.child[char];
}

// 반복이 끝났으면 true;
current.end = true;

};

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

// i 를 받아 단어 만큼 재귀하는 함수
const searchHelper = (current, i) => {
// i와 단어의 길이가 같으면 종료
if (i === word.length) return current.end;

// 단어 = 찾을 문자의 i번째 단어
const char = word[i];

// 만약 문자가 . 라면
if (char === '.') {
// 해당 현재 것들의 키를 가지고 반복
for (const char of Object.keys(current.child)) {
const children = current.child[char];
// end를 true로 하고 i+1로 재귀
if (searchHelper(children, i + 1)) return true;
}
return false;
}
else {
// 현재 자식에 해당 문자가 없으면 false
if (!(char in current.child)) return false;
// 아니면 한번 더 재귀
return searchHelper(current.child[char], i + 1);
}
}
// 결과 리턴
return searchHelper(this.root, 0);
};

/**
* Your WordDictionary object will be instantiated and called as such:
* var obj = new WordDictionary()
* obj.addWord(word)
* var param_2 = obj.search(word)
*/
Loading