-
-
Notifications
You must be signed in to change notification settings - Fork 195
[Hyun] Week 5 Solution Explanation #108
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
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.
코드가 엄청 깔끔하시네요! 부럽습니다~
return counter | ||
.sorted { lhs, rhs in | ||
lhs.value > rhs.value // 빈도 수를 기준으로 내림차순 정렬 | ||
} | ||
.prefix(k) // 앞에서부터 k만큼 Subarray로 가져옴 | ||
.map(\.key) // 제일 빈도가 많았던 것의 숫자를 가져옴 (Dictionary의 Key값) |
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.
스트림(스위프트에서도 해당 용어가 맞을까요?)로 해결하면 깔끔하겠다 생각했는데 역시나 멋있네요! 👍
@WhiteHyun 님, 아직 PR이 Draft 상태인데, 남은 두 문제 푸실 계획이신가요? |
넵 마저 풀고 Draft 풀겠습니다. |
347. Top K Frequent Elements
Complexities 📈
Explanation 📝
k
만큼의 subarray를 가져옴271. Encode and Decode Strings
238. Product of Array Except Self
Complexities 📈
Explanation 📝
You must write an algorithm that runs in O(n) time and without using the division operation.
를 보고 좌절함P.S.
Space Complexity
를 계산할 때 정답 배열에 관한 크기는 따로 계산하지 않는다는 것을 몰랐습니다.. 그래서 nums의 데이터를 업데이트하며 정답을 어떻게 반환할 수 있을지 계속 고민만 했네요. 😅128. Longest Consecutive Sequence
Complexities 📈
Explanation 📝
n
이라고 칭함n-1
가 집합에 존재하는지 확인(연속적인 수열을 구할 때 자신이 최솟값인지 확인하기 위한 여부)n+1
이 집합에 존재하는지 확인, 그 이후 집합에 존재하기 전까지 해당 요소의 값을 1씩 더함. 이를m
이라고 칭함2.
m
이 구해졌다면,n...m-1
이 최종 연속 수열의 길이가 됨. 따라서 이러한 수열의 길이를 구하고, 최댓값을 저장하여 리턴하였음15. 3Sum
Complexities 📈
Explanation 📝
저에게는 너무 어려운 문제였습니다..
처음에는 3중 for문이 바로 떠올랐으나, 시간초과가 날 것 같아 시도하지 않았고, 시간복잡도를 줄일 수 있는 방법이 무엇일지 계속 고민하다가 답지를 찾아보게 되었어요 ㅎㅎ..