-
-
Notifications
You must be signed in to change notification settings - Fork 195
[clara-shin] WEEK 06 solutions #1420
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
Conversation
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.
문제 풀이 로직, 복잡도 분석, 그리고 코드 라인별 코멘트를 잘 정리하신 걸 보고 많이 배우고 갑니다...! 🤩
*/ | ||
var isValid = function (s) { | ||
// 빈 문자열이나 홀수 길이는 유효하지 않음 | ||
if (s.length === 0 || s.length % 2 !== 0) 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.
이렇게 빠르게 종료할 수 있는 조건을 추가해두면 런타임 측면에서 확실히 좋아질 것 같네요!
} else if (char === '{') { | ||
stack.push('}'); | ||
} else if (char === '[') { | ||
stack.push(']'); |
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.
if
문부터 두 번째 else if
문까지 여는 괄호를 판단하는 동일한 조건과 stack.push()
라는 동일한 동작을 구현하고 있기 때문에, 다음과 같이 해시맵을 사용한다면 반복되는 분기문 코드를 조금 더 줄일 수도 있을 것 같습니다~! (다만, 제가 자바스크립트를 잘 몰라서 문법에 오류가 있을 수 있습니다.. 😭)
const mapping = {
'(': ')',
'{': '}',
'[': ']'
};
...
for (let char of s) {
if (char in mapping) {
stack.push(mapping[char]);
} else {
...
}
}
}
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!