-
Notifications
You must be signed in to change notification settings - Fork 126
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
[재호] WEEK 06 Solutions #462
Conversation
// 1. s의 길이만큼 순회를 하면서 | ||
for (const char of s) { | ||
// 2. 열린 괄호라면 stack에 짝지어진 닫힌 괄호를 저장 | ||
// 3. 닫힌 괄호라면 stack에서 꺼낸 것과 동일한지 확인 | ||
switch (char) { | ||
case "(": | ||
case "{": | ||
case "[": | ||
stack.push(map[char]); | ||
break; | ||
case "}": | ||
case ")": | ||
case "]": | ||
if (stack.pop() !== char) { | ||
return false; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
괄호 문제에서 switch
쓸 생각은 못해봤는데 신선하네요!
const ROW = matrix.length; | ||
const COLUMN = matrix[0].length; | ||
// 우하좌상 순서 | ||
const DIRECTION = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 상수로 선언한 덕분에 가독성이 확 올라가는 군요. 감사합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전반적으로 코드 가독성이 아주 좋다고 생각했어요. 변수 선언도 변수 이름도 명확하고 주석으로 추가 설명까지 잘 해주셔서 알고리즘을 이해하는데 손색 없었습니다 🙇♂️
|
||
/** | ||
* TC: O(N) | ||
* SC: O(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addWord
는 단어 길이에 비례해 공간을 사용하는 것 같은데, 상수인 이유가 있을까용?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 순간적으로 linked list로 착각했었네요 😅
O(N)으로 수정해두었습니다!
// 1. s의 길이만큼 순회를 하면서 | ||
for (const char of s) { | ||
// 2. 열린 괄호라면 stack에 짝지어진 닫힌 괄호를 저장 | ||
// 3. 닫힌 괄호라면 stack에서 꺼낸 것과 동일한지 확인 | ||
switch (char) { | ||
case "(": | ||
case "{": | ||
case "[": | ||
stack.push(map[char]); | ||
break; | ||
case "}": | ||
case ")": | ||
case "]": | ||
if (stack.pop() !== char) { | ||
return false; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
괄호 문제에서 switch
쓸 생각은 못해봤는데 신선하네요!
} | ||
} | ||
|
||
return Math.max(...longestLength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
마지막에 Math.max
를 통해 longestLength
배열의 최대값을 구하는 것보다 for 문 안에서 최대값을 갱신해주는 것이 연산량이 줄어들 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
마지막 순회를 줄일수 있네요!
수정해서 반영했습니다!
감사합니다~!
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.