-
-
Notifications
You must be signed in to change notification settings - Fork 195
[bky373] 10th week solutions #166
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
아고 드래프트로 올린다는 게 실수로 오픈했네요 일단 드래프트로 변경하겠습니다 |
|
||
/* | ||
* Approach 2. | ||
* time: O(n^2) |
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.
while (0 <= start && end < s.length() && s.charAt(start) == s.charAt(end)) {
이 부분이 끝까지 가지 않을 확률이 높아서 평균적으로 n^2 보다는 작을 것 같은데
혹시 이 부분도 고려해보셨을까요?
저는 일단
시간 복잡도는 평균적으로 O(n)이다. palindrome 의 길이가 n 에 가까워질수록 시간 복잡도는 O(n^2) 에 가까워 진다.
이렇게 적어보긴 했네요
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.
아하 저는 시간 복잡도를 하나의 값으로 설명해야 한다면, 보수적으로 가장 오래 걸리는 경우의 값을 취해야 한다고 생각했습니다!
다만 굳이 하나의 값으로 설명하지 않아도 된다면, 종훈님이 올려주신 아래 문장이 적절해 보이네요!
시간 복잡도는 평균적으로 O(n)이다. palindrome 의 길이가 n 에 가까워질수록 시간 복잡도는 O(n^2) 에 가까워 진다.
|
||
start = i; | ||
end = i + 1; | ||
while (0 <= start && end < s.length() && s.charAt(start) == s.charAt(end)) { |
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.
이 while 블록이 위에 있는 while 블록과 완전히 동일한것 같은데
맞다면 중복을 제거해보면 어떠실까요?
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.
네 맞습니다 동일한 블록입니다 중복을 제거해봐도 좋겠네요 감사합니다!
/* | ||
* Approach 2-2. | ||
* time: 시간 복잡도는 평균적으로 O(n)이고, palindrome 의 길이가 n 에 가까워지면 시간 복잡도 역시 O(n^2) 에 가까워 진다. | ||
* space: O(1) | ||
*/ | ||
class Solution { |
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.
@dev-jonghoonpark
리뷰 주신 부분 여기에 반영했습니다~ 덕분에 코드가 훨씬 깔끔해졌네요!
610f418
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.
수고 많으셨습니다!
Graph Valid Tree
Number of Connected Components in an Undirected Graph
House Robber
House Robber II
Longest Palindromic Substring