-
-
Notifications
You must be signed in to change notification settings - Fork 245
[haklee] week 3 #380
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
[haklee] week 3 #380
Conversation
return [ind_dict[i], ind_dict[target - i]] | ||
|
||
# 여기에 도달했다면 i와 target - i값이 같음. | ||
if (x := nums.index(i)) != ind_dict[target - i]: |
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.
Walrus 연산자를 참 잘 쓰시는 것 같아요 :=
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.
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.
3주간 본 풀이들 중에서 가장 인상깊었습니다 := )
def climbStairs(self, n: int) -> int: | ||
a, b = 1, 1 | ||
for _ in range(n - 1): | ||
a, b = b, a + b | ||
return b |
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.
이 풀이 보고 아 맞다 이거 피보나치였지 하고는 문제풀이 지원했습니다
아이디어: | ||
다음의 등식을 보자. | ||
|
||
x / y = 2^(log2(x)) / 2^(log2(y)) = 2^(log2(x)-log2(y)) | ||
|
||
즉, 우리는 나누기 연산을 power, log, - 연산으로 우회 가능하다. |
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.
무섭습니다... 제 생각에 이 문제의 의도는 크게는 공간복잡도를 희생해서 시간복잡도를 어떻게 향상시킬 것인가, 좁게는 prefix와 suffix를 사용해서 구간의 곱에 대한 정보를 저장해서 이후 연산에 사용하는 방법이라 생각합니다. 이런 방향으로 생각해서 다른 풀이도 도전해보시면 어떨까요
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.
누적합을 쓰는 것과 비슷한 방식으로 푸는 것도 좋았겠지만, 이번에는 이렇게 문제를 뚫어본 것으로 만족하고 쉬어가보겠습니다..
if (x := nums.index(i)) != ind_dict[target - i]: | ||
# 첫, 마지막 등장 인덱스가 다를 경우, 이 두 숫자를 리턴. | ||
return [x, ind_dict[target - i]] |
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.
이 부분 walrus 좋은 것 같습니다 저도 다음에 이렇게 써보고 싶어요
# 마지막에 중복된 경우를 제거해준다. | ||
return list(set([tuple(sorted(i)) for i in dp[target]])) |
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[target]의 최대 길이는 target의 최대 크기 / candidates의 최소 값이므로 40 / 2 = 20
list * set * tuple * sorted 하면 시간복잡도가 O(m * m * n * nlogn) 이니 문제에서 candidates의 원소들이 distinct하다는 점을 무시하고 어림해도 대략 20만 정도로 충분히 안전한 값이긴 하지만 target이나 candidates가 커지면 모르겠습니다
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.
동의합니다. 만약 현실에서 이 문제를 좀 더 빡센 조건이 걸려있는 상태로 마주쳤다면 아마 이 풀이로는 부분점수밖에 못 긁어갔을 것입니다. 그래서 좀 더 시간을 단축하는 방법을 찾다가 아래의 다른 솔루션들을 구현하지 않았을까 생각했습니다.
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.
수고하셨습니다!
No description provided.