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
36 changes: 36 additions & 0 deletions container-with-most-water/hozzijeong.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function(height) {
// x축이 가장 길면서 y축 역시 가장 높은 즉 높이가 가장 높은 값을 찾으라는 의미.
// startIndex값과 그 값에 해당하는 height를 받고
// endIndex의 값과 그 값에 해당하는 height를 받는다.
// 여기서 가장 큰 점은 startIndex와 endIndex가 멀면 멀수록 좋다
// 그리고 그 값을 하나씩 줄여가면서 더 큰 값을 찾아 적용한다

let max = 0;

let startIndex = 0;
let endIndex = height.length -1;

while(startIndex < endIndex){
const startHeight = height[startIndex];
const endHeight = height[endIndex];

const xLength = endIndex - startIndex;
const minHeight = Math.min(startHeight, endHeight);

const size = xLength * minHeight;

max = Math.max(size,max);

if(startHeight >= endHeight){
endIndex -=1;
}else{
startIndex +=1;
}
};

return max
};
39 changes: 39 additions & 0 deletions design-add-and-search-words-data-structure/hozzijeong.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

var WordDictionary = function() {
const dictionary = new Set('');

this.dictionary = dictionary
};

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

/**
* @param {string} word
* @return {boolean}
*/
WordDictionary.prototype.search = function(word) {
if(word.includes('.')){
const dictionaryList = [...this.dictionary];

return dictionaryList.some((dic) => {
if(dic.length !== word.length) return false;

return [...dic].every((char, index) => word[index] === '.' ? true : word[index] === char)
})
};

return this.dictionary.has(word)
};

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

Choose a reason for hiding this comment

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

안녕하세요! 해당 풀이도 좋지만 Hashmap를 사용하면 좀 더 간결하게 작성할 수 있을거 같아요!

/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function(s) {
  const closeMap = {
    '(': ')',
    '{': '}',
    '[': ']'
  };

  const stack = [];

  for (const ch of s) {
    if (ch in closeMap) {
      stack.push(closeMap[ch]);        // 기대되는 닫는 괄호를 push
    } else {
      if (stack.pop() !== ch) return false; // 닫는 괄호면 바로 비교
    }
  }

  return stack.length === 0;
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @param {string} s
* @return {boolean}
*/
var isValid = function(s) {
const smallBracket = ['(',')'];
const middleBracket = ['{','}'];
const largeBracket = ['[',']'];


const leftStack = [];

for(const char of s) {
if(char === smallBracket[0]){
leftStack.push(smallBracket[1])
}else if (char === middleBracket[0]){
leftStack.push(middleBracket[1])
}else if(char === largeBracket[0]){
leftStack.push(largeBracket[1])
}else{
const last = leftStack.pop();
if(char === smallBracket[1] && last !== char) return false;
if(char === middleBracket[1] && last !== char) return false;
if(char === largeBracket[1] && last !== char) return false;
}
}


return leftStack.length === 0
};