Skip to content
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

[TONY] WEEK 06 Solutions #465

Merged
merged 5 commits into from
Sep 21, 2024
Merged

[TONY] WEEK 06 Solutions #465

merged 5 commits into from
Sep 21, 2024

Conversation

TonyKim9401
Copy link
Contributor

@TonyKim9401 TonyKim9401 commented Sep 16, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@github-actions github-actions bot added the java label Sep 16, 2024
@TonyKim9401 TonyKim9401 changed the title Valid Parentheses [TONY] WEEK 06 SOLUTIONS Sep 16, 2024
@TonyKim9401 TonyKim9401 changed the title [TONY] WEEK 06 SOLUTIONS [TONY] WEEK 06 Solutions Sep 16, 2024
Comment on lines +3 to +4
// SC: O(n)
// -> n = s.length / 2
Copy link
Contributor

Choose a reason for hiding this comment

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

공간복잡도를 왜 이렇게 생각하셨는지 설명 부탁드려도 될까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stack에 데이터가 들어가는 경우는 현재 값이 (, {, [ 인 경우 뿐이고, 최악의 경우(((({{{[[[ 같은 값이 주어지더라도, 여전히 상수값이기에 공간 복잡도는 O(n)이라고 생각합니다!

Copy link
Contributor

@obzva obzva Sep 19, 2024

Choose a reason for hiding this comment

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

답변 감사합니다 토니님 :)

O(N)의 형태로 사용 공간이 증가한다는 것은 이해 및 동의합니다

여전히 제가 이해를 하지 못한 부분이 있어서 더 질문 드리고 싶습니다

  1. n = s.length / 2 이 부분에 대해서 더 자세히 설명 부탁 드려도 될까요?

  2. 최악의 경우(((({{{[[[ 같은 값이 주어지더라도, 여전히 상수값에서 상수값이라는 표현에 대해 잘 이해하지 못했습니다. 1 <= s.length <= 10^4이라는 입력값 제한 조건이 있는데, 이 중에서 10^4를 상수라고 표현하신 걸까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@obzva 스택은 열린 괄호가 들어올 때마다 저장되고 닫힌 괄호가 들어올 때 제거되므로, 스택의 최대 크기는 열린 괄호의 개수만큼이 될겁니다. 따라서, 공간 복잡도는 최악의 경우 O( s.length() / 2) 라고 생각되지만 공간 복잡도계산시 보통 상수를 무시하므로 O(n) 이라고 생각합니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

아하 감사합니다 ㅎㅎㅎ
그치만 s 자체가 ((((((((((((((((((((((((((((((같은 값이 주어진다면 최악의 경우엔 공간 사용량이 s.length() / 2가 아닌 s.length() 아닌가요? 결국 아무 char도 pop되지 않고 스택에 쌓이기만 할테니까요

@obzva obzva marked this pull request as ready for review September 20, 2024 15:50
@obzva obzva requested a review from a team as a code owner September 20, 2024 15:50
Comment on lines +1 to +2
// TC:
// SC:
Copy link
Contributor

Choose a reason for hiding this comment

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

TC, SC 써주시면 더 좋을 것 같습니다~!

Copy link
Contributor Author

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) -> 상수 공간만 사용
으로 봐주시면 감사하겠습니다..!

Comment on lines +1 to +4
// SC: O(n)
// -> n is the length of the given String
// TC: O(n * 26)
// -> n is the length of the given String * the number of alphabets
Copy link
Contributor

Choose a reason for hiding this comment

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

이건 제 의견인데, Big O 분석은 각 함수에 대해 각각 진행하는 것이 더 좋을 것 같습니다

Tony님은 어떻게 생각하세요? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

앗 넵! 저도 각 함수에 대해 각각 진행하는게 좋을것 같습니다. 왜 이렇게 했는지 모르겟네요.. 의견 감사합니다!

@TonyKim9401 TonyKim9401 merged commit 67ab0cd into DaleStudy:main Sep 21, 2024
1 check passed
@DaleSeo
Copy link
Contributor

DaleSeo commented Sep 21, 2024

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.

Shot 2024-09-21 at 19 55 12@2x

@TonyKim9401 체크 리스트와 달리 프로젝트 주차 설정이 안 되어 있네요. 스터디 통계를 집계하는데 중요한 부분이니 다음 PR부터 신경 좀 써주셨으면 좋겠습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants