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

[haklee] week 3 #380

Merged
merged 2 commits into from
Sep 1, 2024
Merged

[haklee] week 3 #380

merged 2 commits into from
Sep 1, 2024

Conversation

haklee
Copy link
Contributor

@haklee haklee commented Aug 25, 2024

No description provided.

return [ind_dict[i], ind_dict[target - i]]

# 여기에 도달했다면 i와 target - i값이 같음.
if (x := nums.index(i)) != ind_dict[target - i]:
Copy link
Contributor

@DaleSeo DaleSeo Aug 26, 2024

Choose a reason for hiding this comment

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

Walrus 연산자를 참 잘 쓰시는 것 같아요 :=

Copy link
Contributor

Choose a reason for hiding this comment

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

왜 walrus인가 했더니 진짜 바다코끼리를 닮았군요 :D
image

@haklee haklee requested a review from a team as a code owner August 27, 2024 13:49
Copy link
Contributor

@lymchgmk lymchgmk left a comment

Choose a reason for hiding this comment

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

3주간 본 풀이들 중에서 가장 인상깊었습니다 := )

Comment on lines +22 to +26
def climbStairs(self, n: int) -> int:
a, b = 1, 1
for _ in range(n - 1):
a, b = b, a + b
return b
Copy link
Contributor

Choose a reason for hiding this comment

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

이 풀이 보고 아 맞다 이거 피보나치였지 하고는 문제풀이 지원했습니다

Comment on lines +64 to +69
아이디어:
다음의 등식을 보자.

x / y = 2^(log2(x)) / 2^(log2(y)) = 2^(log2(x)-log2(y))

즉, 우리는 나누기 연산을 power, log, - 연산으로 우회 가능하다.
Copy link
Contributor

Choose a reason for hiding this comment

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

무섭습니다... 제 생각에 이 문제의 의도는 크게는 공간복잡도를 희생해서 시간복잡도를 어떻게 향상시킬 것인가, 좁게는 prefix와 suffix를 사용해서 구간의 곱에 대한 정보를 저장해서 이후 연산에 사용하는 방법이라 생각합니다. 이런 방향으로 생각해서 다른 풀이도 도전해보시면 어떨까요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

누적합을 쓰는 것과 비슷한 방식으로 푸는 것도 좋았겠지만, 이번에는 이렇게 문제를 뚫어본 것으로 만족하고 쉬어가보겠습니다..

Comment on lines +51 to +53
if (x := nums.index(i)) != ind_dict[target - i]:
# 첫, 마지막 등장 인덱스가 다를 경우, 이 두 숫자를 리턴.
return [x, ind_dict[target - i]]
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분 walrus 좋은 것 같습니다 저도 다음에 이렇게 써보고 싶어요

Comment on lines +55 to +56
# 마지막에 중복된 경우를 제거해준다.
return list(set([tuple(sorted(i)) for i in dp[target]]))
Copy link
Contributor

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가 커지면 모르겠습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

동의합니다. 만약 현실에서 이 문제를 좀 더 빡센 조건이 걸려있는 상태로 마주쳤다면 아마 이 풀이로는 부분점수밖에 못 긁어갔을 것입니다. 그래서 좀 더 시간을 단축하는 방법을 찾다가 아래의 다른 솔루션들을 구현하지 않았을까 생각했습니다.

Copy link
Contributor

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!

@SamTheKorean SamTheKorean merged commit 45e2f8b into DaleStudy:main Sep 1, 2024
1 check passed
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.

5 participants