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
32 changes: 32 additions & 0 deletions container-with-most-water/robinyoon-dev.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers
  • 설명: 이 코드는 양 끝에서 시작하는 두 포인터를 이동시키며 최대 면적을 찾는 방식으로, 투 포인터 패턴에 속합니다. 포인터를 한쪽씩 이동시키며 조건에 따라 최적의 해를 탐색하는 구조입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function (height) {

// 투 포인터
// 왼쪽 포인터, 오른쪽 포인터. lower 라인의 포인터를 움직여야함.

let leftPointer = 0;
let rightPointer = height.length - 1;
let tempMax = 0;

while (leftPointer !== rightPointer) {
let areaHeight = Math.min(height[leftPointer], height[rightPointer]);

let areaWidth = rightPointer - leftPointer;

let waterArea = areaHeight * areaWidth;

tempMax = Math.max(tempMax, waterArea);

if (height[leftPointer] < height[rightPointer]) {
leftPointer++;
} else {
rightPointer--;
}
}

return tempMax;

};
58 changes: 48 additions & 10 deletions valid-parentheses/robinyoon-dev.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Stack / Priority Queue
  • 설명: 이 코드는 스택을 이용하여 괄호의 유효성을 검사하는 문제로, 괄호를 만나면 스택에 넣고, 짝이 맞는 괄호를 만나면 스택에서 제거하는 방식입니다.

Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,63 @@
* @return {boolean}
*/
var isValid = function (s) {

const tempArray = [];
const pairObject = {
const bracketsObj = {
')': '(',
'}': '{',
']': '['
}
const stackArray = [];

for (let i = 0; i < s.length; i++) {

for (const ch of s) {
if (ch === '(' || ch === '{' || ch === '[') {
tempArray.push(ch);
let currentBracket = s[i];
let isRightBracket = currentBracket in bracketsObj;

if (!isRightBracket) {
stackArray.push(currentBracket);
continue;
}

let isPair = stackArray[stackArray.length - 1] == bracketsObj[currentBracket];

if (isPair) {
stackArray.pop();
} else {
if (tempArray.pop() !== pairObject[ch]) {
return false;
}
return false;
}
}

return tempArray.length === 0;
return stackArray.length === 0

};


// -----6기 활동 시의 풀이----
// /**
// * @param {string} s
// * @return {boolean}
// */
// var isValid = function (s) {

// const tempArray = [];
// const pairObject = {
// ')': '(',
// '}': '{',
// ']': '['
// }

// for (const ch of s) {
// if (ch === '(' || ch === '{' || ch === '[') {
// tempArray.push(ch);
// } else {
// if (tempArray.pop() !== pairObject[ch]) {
// return false;
// }
// }
// }

// return tempArray.length === 0;
// };



Loading