Skip to content

[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

Merged
merged 5 commits into from
May 9, 2025
Merged

[clara-shin] WEEK 06 solutions #1420

merged 5 commits into from
May 9, 2025

Conversation

clara-shin
Copy link
Contributor

@clara-shin clara-shin commented May 4, 2025

답안 제출 문제

작성자 체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

Copy link
Contributor

@seungriyou seungriyou left a comment

Choose a reason for hiding this comment

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

깔끔한 코드와 풀이법에서 많이 배웠습니다! 이번 한 주도 화이팅이에요~! 🚀 🍀

*
* 양쪽 끝에서 시작하는 두 포인터를 사용
* 투 포인터 방식이 효율적인 이유: 항상 더 작은 높이를 가진 쪽을 이동시키면 최대 면적을 놓치지 않기 때문
* 더 큰 높이 쪽을 이동시키면 가로 길이는 줄어들고, 세로 길이는 같거나 더 작아져서 면적이 줄어들 수밖에 없음
Copy link
Contributor

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;
Copy link
Contributor

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(']');
Copy link
Contributor

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 {
    ...
    }
  }
}

@clara-shin clara-shin moved this from Solving to In Review in 리트코드 스터디 4기 May 8, 2025
@clara-shin clara-shin merged commit e47d685 into DaleStudy:main May 9, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 4기 May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants