Skip to content

Conversation

HodaeSsi
Copy link
Contributor

@HodaeSsi HodaeSsi commented Dec 28, 2024

답안 제출 문제

체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@HodaeSsi HodaeSsi requested a review from a team as a code owner December 28, 2024 13:29
@github-actions github-actions bot added the py label Dec 28, 2024
@donghyeon95
Copy link
Contributor

@HodaeSsi 님 요번 주도 수고 많으셨습니다.
좋은 풀이 잘 보고 갑니다.

Copy link
Contributor

@donghyeon95 donghyeon95 left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

말씀하신 파이썬의 위대함인 것 같습니다 ㅎㅎ
엄청 간단하게 풀리네요

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

모든 합 경우에서 조합 구하는 방식으로 풀면 되는 거군요.
저는 시간이 많이 걸릴 것 같아서 target을 쪼개는 방식으로 했는데,
중복을 제거 하는 게 좀 힘들었던 거 같습니다 ㅜㅜ

좋은 풀이 잘 봤습니다.

Copy link
Contributor Author

@HodaeSsi HodaeSsi Dec 28, 2024

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]
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

되게 가독성 높은 풀이인 거 같습니다.
같은 방법인데 자바로 깔끔하게 풀려면 어떻게 해야 할까요?

Copy link
Contributor Author

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에 의해 작성된 코드입니다. 😉

@HodaeSsi HodaeSsi merged commit dfd507b into DaleStudy:main Dec 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants