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

[HerrineKim] Week 6 #906

Merged
merged 2 commits into from
Jan 17, 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
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;
};
Loading