Skip to content

Commit

Permalink
Merge pull request #906 from HerrineKim/main
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrineKim authored Jan 17, 2025
2 parents a41c907 + c2bf12a commit 1ef7736
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
26 changes: 26 additions & 0 deletions container-with-most-water/HerrineKim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
// ๊ณต๊ฐ„๋ณต์žก๋„: O(1)

/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function (height) {
let maxWater = 0;
let left = 0;
let right = height.length - 1;

while (left < right) {
const lowerHeight = Math.min(height[left], height[right]);
const width = right - left;
maxWater = Math.max(maxWater, lowerHeight * width);

if (height[left] < height[right]) {
left++;
} else {
right--;
}
}

return maxWater;
};
33 changes: 33 additions & 0 deletions valid-parentheses/HerrineKim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
// ๊ณต๊ฐ„๋ณต์žก๋„: O(n)

// ์Šคํƒ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ด„ํ˜ธ์˜ ์œ ํšจ์„ฑ์„ ๊ฒ€์‚ฌ
// ๊ด„ํ˜ธ๊ฐ€ ์—ด๋ฆฌ๋ฉด ์Šคํƒ์— ์ถ”๊ฐ€ํ•˜๊ณ  ๋‹ซํžˆ๋ฉด ์Šคํƒ์—์„œ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ๊บผ๋‚ด์„œ ์ง์ด ๋งž๋Š”์ง€ ํ™•์ธ
// ์Šคํƒ์ด ๋น„์–ด์žˆ์œผ๋ฉด ์œ ํšจํ•œ ๊ด„ํ˜ธ ๋ฌธ์ž์—ด

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

for (const char of s) {
if (char in bracketPairs) {
const lastChar = bracketStack.pop();

if (lastChar !== bracketPairs[char]) {
return false;
}
} else {
bracketStack.push(char);
}
}

return bracketStack.length === 0;
};

0 comments on commit 1ef7736

Please sign in to comment.