Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 29 additions & 0 deletions container-with-most-water/Jeehay28.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @param {number[]} height
* @return {number}
*/

// Time Complexity: O(n)
// Space Complexity: O(1)
var maxArea = function (height) {
let start = 0;
let end = height.length - 1;
let maxArea = 0;

while (start < end) {
const area = (end - start) * Math.min(height[start], height[end]);
maxArea = Math.max(area, maxArea);

// The shorter height limits the area.
// By moving the pointer associated with the shorter height,
// the algorithm maximizes the chance of finding a taller line that can increase the area.
// This is the essence of the two-pointer strategy for the container problem.
if (height[start] < height[end]) {
start += 1;
} else {
end -= 1;
}
}
return maxArea;
};

35 changes: 35 additions & 0 deletions valid-parentheses/Jeehay28.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @param {string} s
* @return {boolean}
*/

// Time Complexity: O(n)
// Space Complexity: O(n)
var isValid = function (s) {
const obj = {
"(" : ")",
"{" : "}",
"[" : "]",
};

let stack = [];

for (any of s) {
// open bracket
if (obj[any]) {
stack.push(any);
} else {
// close bracket
if (stack.length === 0) {
return false;
} else if (obj[stack[stack.length - 1]] !== any) {
return false;
} else {
stack.pop();
}
}
}
return stack.length === 0 ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

return stack.length === 0 만 해도 true, false 로 반환되지 않을까요? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

아, 그렇네요. 감사합니다.

};


Loading