-
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
[TONY] WEEK 5 Solution #451
Conversation
@@ -0,0 +1,25 @@ | |||
// TC: O(n) | |||
// SC: O(n * m) |
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.
질문
m
은 strs
배열 내 원소의 평균~최대 크기라고 보면 될까요?
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.
아뇨! 제 풀이 방식에서는 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); |
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.
찾아보니 JAVA의 Arrays.sort
method도 퀵소트를 사용하는 것 같은데, 이 부분에 대한 계산이 누락된 것 같아 보입니다
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.
앗 감사합니다!
주어진 문자열 n에서 각 요소를 m으로 두고 sort하면 Java에서는 m log m 시간이 걸립니다.
따라서 시간 복잡도가 O(n * m log m)을 가지게 되겠네요.
통찰력 감탄합니다 감사합니다!! 💯
Time Complexity re-calculation
public boolean wordBreak(String s, List<String> wordDict) { | ||
Set<String> set = new HashSet(wordDict); | ||
|
||
boolean[] dp = new boolean[s.length() + 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.
dp 배열을 어떻게 정의하셨는지 설명을 적어주시면 리뷰하기 좀 더 수월할 것 같습니다 감사합니다 :)
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.
""의 경우 항상 true이므로 0을 true로 두고, 배열의 마지막이 true이면 모든 문자가 존재한다는 판단으로
주어진 문자열의 길이 + 1
으로 정의해 보았습니다!
dp[0] = true; | ||
|
||
for (int i = 1; i <= s.length(); i++) { | ||
for (int j = 0; j < i; j++) { |
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.
1 <= s.length <= 300
1 <= wordDict.length <= 1000
s
의 모든 substring을 조회하는 것이 wordDict
를 조회하는 것보다 더 빠르겠군요..?
입력 조건을 더 잘 봐야겠다는 생각이 듭니다 감사합니다 :)
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.
저도 리팩토링 하면서 발견한거라 처음에 wordDict 조회하는걸로 풀었습니다 ㅎㅎ
코드 리뷰 감사합니다!
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.
고생하셨습니다 :D
// TC: O(n^2) | ||
// -> use 2 for-loops to search |
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.
@TonyKim9401 입력 값이 두 개 이상일 때는 n
이 무엇을 의미하는지 명시해주시는 것이 좋을 것 같습니다!
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
로 설정해주세요.