Skip to content

[seungseung88] WEEK 01 solutions #1136

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

Merged
merged 7 commits into from
Apr 5, 2025
Merged

Conversation

seungseung88
Copy link
Contributor

@seungseung88 seungseung88 commented Mar 30, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

Sorry, something went wrong.

@seungseung88 seungseung88 marked this pull request as ready for review April 3, 2025 14:16
Copy link
Member

@jeongwoo903 jeongwoo903 left a comment

Choose a reason for hiding this comment

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

공간복잡도랑 시간복잡도까지 다 파악해서 기록해 두시는게 대단하신 것 같아요!!
첫 주 마지막 문제까지 잘 하시길 응원합니다!! 고생하셨어요~

Comment on lines 4 to 21
const twoSum = (nums, target) => {
// 배열을 한 번 순회
// {값: 인덱스} 형태로 저장
const indicies = {};

for (let i = 0; i < nums.length; i += 1) {
// target숫자에서 현재 숫자를 뺀 숫자가 존재하는지 확인한다.
const targetIndex = nums.indexOf(target - nums[i]);
// targetIndex가 존재하고(-1이 아님), 현재 숫자와 같은 인덱스 숫자가 아니라면 반환한다.
if (targetIndex !== -1 && i !== targetIndex) {
return [i, targetIndex];
// 타겟값에서 현재 가리키는 숫자를 뺀 값을 저장
const complement = target - nums[i];

// complement가 indicies안에 존재하면 해당 값을 반환
if (complement in indicies) {
const j = indicies[complement];
return [j, i];
}
// 존재 하지 않으면 값과 인덱스 형태로 저장 ex> { 11: 0, 15: 1, 2: 2 }
indicies[nums[i]] = i;
console.log(indicies);
}
};
Copy link
Member

Choose a reason for hiding this comment

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

객체를 이용해서 푸셨네요!
저는 Map을 통해서 관계를 그렸는데 다양한 풀이법이 있는 것 같네요 ☺️

Comment on lines 24 to 29
const answer = [];

// 상위 k개의 숫자를 answer 배열에 저장
for (let i = 0; i < k; i += 1) {
answer[i] = Number(sortedCountNums[i][0]);
}
Copy link
Member

Choose a reason for hiding this comment

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

선언적으로 처리한다면 다음과 같은 방식으로 처리할수도 있을 것 같아요!

Suggested change
const answer = [];
// 상위 k개의 숫자를 answer 배열에 저장
for (let i = 0; i < k; i += 1) {
answer[i] = Number(sortedCountNums[i][0]);
}
const answer = Array.from(sortedCountNums.entries())
.sort((a, b) => b[1] - a[1])
.slice(0, k)
.map(item => item[0]);

// 연속되는 배열에서 가장 긴 배열을 저장
while (set.has(v + cnt)) {
cnt += 1;
longest = longest < cnt ? cnt : longest;
Copy link
Member

Choose a reason for hiding this comment

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

의도는 충분히 알겠으나 단순히 아래 코드가 가독성이 더 나을수도 있겠다는 생각이 드네요 🤔

if (cnt > longest) {
  longest = cnt;
}

@seungseung88 seungseung88 moved this from Solving to In Review in 리트코드 스터디 4기 Apr 4, 2025
- longestConsecutive - bucket sort 사용
- top-k-frequent-elements - 코드 최적화
@seungseung88 seungseung88 merged commit a907843 into DaleStudy:main Apr 5, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 4기 Apr 5, 2025
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.

None yet

2 participants