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 5 Solution #451

Merged
merged 6 commits into from
Sep 13, 2024
Merged

[TONY] WEEK 5 Solution #451

merged 6 commits into from
Sep 13, 2024

Conversation

TonyKim9401
Copy link
Contributor

@TonyKim9401 TonyKim9401 commented Sep 10, 2024

답안 제출 문제

체크 리스트

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

@TonyKim9401 TonyKim9401 self-assigned this Sep 10, 2024
@TonyKim9401 TonyKim9401 requested a review from sun912 September 10, 2024 16:51
@@ -0,0 +1,25 @@
// TC: O(n)
// SC: O(n * m)
Copy link
Contributor

Choose a reason for hiding this comment

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

질문

mstrs 배열 내 원소의 평균~최대 크기라고 보면 될까요?

Copy link
Contributor Author

@TonyKim9401 TonyKim9401 Sep 13, 2024

Choose a reason for hiding this comment

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

아뇨! 제 풀이 방식에서는 map을 사용하고 있고
Key: String, Value: List<String> 을 사용하고 있습니다.
즉 n개의 key 값들에 m개의 value가 공간을 차지하는걸 최대로 보고 n * m 으로 공간 복잡도를 구했습니다!


for (int i = 0; i < strs.length; i++) {
char[] charArray = strs[i].toCharArray();
Arrays.sort(charArray);
Copy link
Contributor

Choose a reason for hiding this comment

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

찾아보니 JAVA의 Arrays.sort method도 퀵소트를 사용하는 것 같은데, 이 부분에 대한 계산이 누락된 것 같아 보입니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

앗 감사합니다!
주어진 문자열 n에서 각 요소를 m으로 두고 sort하면 Java에서는 m log m 시간이 걸립니다.
따라서 시간 복잡도가 O(n * m log m)을 가지게 되겠네요.
통찰력 감탄합니다 감사합니다!! 💯

@TonyKim9401 TonyKim9401 requested a review from DaleSeo September 13, 2024 02:49
  Time Complexity re-calculation
@TonyKim9401 TonyKim9401 requested a review from obzva September 13, 2024 02:54
@TonyKim9401 TonyKim9401 marked this pull request as ready for review September 13, 2024 02:57
@TonyKim9401 TonyKim9401 requested a review from a team as a code owner September 13, 2024 02:57
public boolean wordBreak(String s, List<String> wordDict) {
Set<String> set = new HashSet(wordDict);

boolean[] dp = new boolean[s.length() + 1];
Copy link
Contributor

Choose a reason for hiding this comment

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

dp 배열을 어떻게 정의하셨는지 설명을 적어주시면 리뷰하기 좀 더 수월할 것 같습니다 감사합니다 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

""의 경우 항상 true이므로 0을 true로 두고, 배열의 마지막이 true이면 모든 문자가 존재한다는 판단으로
주어진 문자열의 길이 + 1 으로 정의해 보았습니다!

dp[0] = true;

for (int i = 1; i <= s.length(); i++) {
for (int j = 0; j < i; j++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

1 <= s.length <= 300
1 <= wordDict.length <= 1000

s의 모든 substring을 조회하는 것이 wordDict를 조회하는 것보다 더 빠르겠군요..?

입력 조건을 더 잘 봐야겠다는 생각이 듭니다 감사합니다 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

저도 리팩토링 하면서 발견한거라 처음에 wordDict 조회하는걸로 풀었습니다 ㅎㅎ
코드 리뷰 감사합니다!

Copy link
Contributor

@obzva obzva left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 :D

@TonyKim9401 TonyKim9401 merged commit 41435c7 into DaleStudy:main Sep 13, 2024
1 check passed
Comment on lines +1 to +2
// TC: O(n^2)
// -> use 2 for-loops to search
Copy link
Contributor

Choose a reason for hiding this comment

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

@TonyKim9401 입력 값이 두 개 이상일 때는 n이 무엇을 의미하는지 명시해주시는 것이 좋을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

다음부터는 명시 하도록 하겠습니다!

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

Successfully merging this pull request may close these issues.

3 participants