-
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
[HodaeSsi] Week3 #804
[HodaeSsi] Week3 #804
Conversation
@HodaeSsi 님 요번 주도 수고 많으셨습니다. |
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(1) (32bit) | ||
class Solution: | ||
def reverseBits(self, n: int) -> int: | ||
return int(bin(n)[2:].zfill(32)[::-1], 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.
말씀하신 파이썬의 위대함인 것 같습니다 ㅎㅎ
엄청 간단하게 풀리네요
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.
동현님도 파이썬 하실래요?! 😆
for combination in dp[num - candidate]: | ||
temp = combination.copy() | ||
temp.extend([candidate]) | ||
dp[num].append(temp) |
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.
모든 합 경우에서 조합 구하는 방식으로 풀면 되는 거군요.
저는 시간이 많이 걸릴 것 같아서 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를 생각해보는 방식으로 해보고 있긴 합니다!
if idx == 0: | ||
prefix[idx] = nums[idx] | ||
else: | ||
prefix[idx] = prefix[idx - 1] * nums[idx] |
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부터 시작하면 조건문이 생략될 수 있지 않을까 합니다
for i, num in enumerate(nums): | ||
if target - num in seen: | ||
return [seen[target - num], i] | ||
seen[num] = 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.
되게 가독성 높은 풀이인 거 같습니다.
같은 방법인데 자바로 깔끔하게 풀려면 어떻게 해야 할까요?
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.
import java.util.HashMap;
import java.util.Map;
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> seen = new HashMap<>(); // {num: idx, ...}
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (seen.containsKey(complement)) {
return new int[] {seen.get(complement), i};
}
seen.put(nums[i], i);
}
return new int[] {}; // 적절한 결과가 없으면 빈 배열 반환
}
}
*이 코드는 gpt에 의해 작성된 코드입니다. 😉
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.