Skip to content

Conversation

@JangAyeon
Copy link
Contributor

@JangAyeon JangAyeon commented Nov 6, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@JangAyeon JangAyeon requested a review from ys-han00 November 10, 2025 22:42
Copy link
Contributor

@ys-han00 ys-han00 left a comment

Choose a reason for hiding this comment

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

@JangAyeon

안녕하세요~! 가이드에 따르면 리뷰 경험이 없는 제가 리뷰어더라구요 😅

제가 아는 것도 적고 이번이 첫 리뷰다 보니, 리뷰에 많이 부족한 점이 있을 것 같아 미리 사죄드립니다....

최대한 제가 생각할 수 있는 선에서 궁금한 점과 피드백 남겨요!

이와 관련해서 질문 있으실 경우, Discord나 PR 댓글로 멘션 주세요! (이상하다 싶으시면 넘어가셔도 괜찮습니다 😄)

첫 주 문제 풀이 수고하셨습니다!

Comment on lines +9 to +13
for (let e of nums) {
const v = counter.has(e) ? counter.get(e) + 1 : 1;
counter.set(e, v);
}
const answer = [...counter.values()].some((item) => item >= 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

모두 순회하면서 counternums를 넣기 보다는, 조건문을 통해 1보다 커지는 경우를 바로 return 하도록 처리하면 중복이 맨 뒤에 있을 때 좀 더 효율적으로 처리 가능할 것 같습니다!

};
// 두번째 제출
var containsDuplicate = function (nums) {
return new Set(nums).size !== nums.length;
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.

말씀해주신 것처럼 중복을 발견하는 즉시 return 하면,
특히 중복 값이 배열 뒤쪽에 있을 때 전체 순회를 하지 않아도 되어 더 효율적이고,
시간 단축 + 불필요한 순회 제거라는 큰 이점이 있어 공감합니다!

Copy link
Contributor

Choose a reason for hiding this comment

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

반복문 하나만 사용해도 풀리는 문제였네요.

저는 dp로 풀기 위해 반복문을 하나 더 사용했는데, 하나 알아갑니다!

Comment on lines +8 to +13
let [rob1, rob2] = [0, 0];
for (let num of nums) {
let temp = Math.max(num + rob1, rob2);
rob1 = rob2;
rob2 = temp;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

아래와 같이 로직을 이해했는데, 맞을까요?

  • num + rob1: 위치가 i인 집을 털고, i-2 집까지 털어온 최댓값을 더한 값
  • rob2: 위치 i 집을 포기하고, i-1 집까지 오면서 얻은 최댓값

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네, 정확하게 이해하신 게 맞습니다!

  • num + rob1 → 현재 집(i)을 털었을 때, 두 칸 전(i-2)까지의 최대 금액인 rob1과 현재 집의 금액을 더한 값
  • rob2 → 현재 집(i)을 털지 않았을 때, 바로 전 집(i-1)까지의 최대 금액

그래서 두 값 중 더 큰 값을 선택해 temp에 저장하고,
rob1, rob2를 각각 i-1, i 시점의 상태로 업데이트하는 구조입니다.

정확하게 로직을 짚어주셔서 감사합니다

Copy link
Contributor

Choose a reason for hiding this comment

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

간단 명료한 풀이네요👍

* @return {number[]}
*/
var topKFrequent = function (nums, k) {
nums = nums.sort((a, b) => a - b);
Copy link
Contributor

Choose a reason for hiding this comment

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

nums를 정렬하신 이유가 궁금합니다!

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 +8 to +16
var twoSum = function (nums, target) {
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
return [i, j];
}
}
}
};
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.

맞아요! 이 문제는 가장 직관적이고 구현도 간단한 풀이로 브루트포스 방식을 사용해보았는데
입력 크기가 커도 이중 반복문으로 시간 초과가 나지 않았습니다. ㅎㅎ
나중에 확장하거나 최적화할 때는 해시맵 풀이로 바꿔서도 풀이해보았습니다 🙂

Comment on lines +19 to +29
var twoSum = function (nums, target) {
const map = new Map(); // {값: 인덱스}

for (let i = 0; i < nums.length; i++) {
const complement = target - nums[i]; // 필요한 짝 계산
if (map.has(complement)) {
return [map.get(complement), i]; // 이전에 complement가 있었으면 바로 반환
}
map.set(nums[i], 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.

오 저는 투포인터 방식은 생각하지 못했는데, 서로 다른 방식으로 풀이 공유할 수 있어서 좋네요.
코멘트 감사합니다! 🙌

@JangAyeon JangAyeon moved this from Solving to In Review in 리트코드 스터디 6기 Nov 14, 2025
@JangAyeon JangAyeon merged commit 6b69bb9 into DaleStudy:main Nov 15, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 6기 Nov 15, 2025
@ys-han00
Copy link
Contributor

코멘트 다 읽고 Approved 변경했습니다!

첫 주 문제 풀이 수고하셨어요~

(상태 변경 후 말씀드리는걸 까먹어서 급하게 지금 달아요 ㅎㅎ)

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.

2 participants