Skip to content

[sm9171] Week01 Solutions #1158

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 8 commits into from
Apr 5, 2025
Merged

[sm9171] Week01 Solutions #1158

merged 8 commits into from
Apr 5, 2025

Conversation

sm9171
Copy link
Contributor

@sm9171 sm9171 commented Mar 31, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

Copy link
Member

@wisdom08 wisdom08 left a comment

Choose a reason for hiding this comment

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

상민님 안녕하세요-!!
잘 지내시나요 ㅎㅎㅎ
지나가다가 리뷰 남겼어요!
끝까지... 파이팅입니다🔥

(github action 실패한 건 아마 마지막 라인에 개행을 안 해서 그런 것 같아요!)

HashSet<Integer> set = new HashSet<>();

for (int i = 0; i < nums.length; i++) {
set.add(nums[i]);
Copy link
Member

Choose a reason for hiding this comment

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

add 할 때 존재하는지 확인하고 바로 return 하는 건 어떨까요?

Copy link
Contributor

Choose a reason for hiding this comment

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

wisdon08님이 좋은 의견 남겨주신것에 저도 동의합니다!
현재는 배열을 끝까지 순회한 후에 중복을 판단하는 구조인것 같아서, 중복을 미리 찾고 빠르게 결과 반환을 하는 구조로 변경하는 것도 좋아 보입니다 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

두 분 의견 감사합니다. 얘기 해주신대로 얼리 리턴을 하니 17ms에서 12ms로 단축 되었네요 :)

for (int i = 0; i < nums.length; i++) {
int num = nums[i];
if (hashMap.containsKey(num)) {
hashMap.put(num, hashMap.get(num) + 1);
Copy link
Member

Choose a reason for hiding this comment

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

hashMap.getOrDefault를 이용해서 가독성을 개선할 수도 있을 거 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getOrDefault를 쓰니 한줄로 줄일 수 있겠네요!

Copy link
Contributor

@yayyz yayyz left a comment

Choose a reason for hiding this comment

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

안녕하세요. 어느덧 1주차 문제풀이 마지막 날이네요.
지금까지 제출해주신 문제들을 기준으로 리뷰 남겼습니다.
다른 문제들도 풀이해주시면 확인 후 추가로 리뷰 진행하겠습니다! 😃

HashSet<Integer> set = new HashSet<>();

for (int i = 0; i < nums.length; i++) {
set.add(nums[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

wisdon08님이 좋은 의견 남겨주신것에 저도 동의합니다!
현재는 배열을 끝까지 순회한 후에 중복을 판단하는 구조인것 같아서, 중복을 미리 찾고 빠르게 결과 반환을 하는 구조로 변경하는 것도 좋아 보입니다 😀

result[i] = list.get(i);
}

return result;
Copy link
Contributor

Choose a reason for hiding this comment

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

위에 List list 부분에서 stream을 사용하신 것 처럼, 반환값도 stream을 활용해보시는 건 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네 array로 타입 변경하는 부분도 스트림을 이용하여 해결해 보았습니다 :)

@sm9171 sm9171 closed this Apr 5, 2025
@github-project-automation github-project-automation bot moved this from Solving to Completed in 리트코드 스터디 4기 Apr 5, 2025
@sm9171 sm9171 reopened this Apr 5, 2025
@sm9171 sm9171 merged commit 94aa3a2 into DaleStudy:main Apr 5, 2025
1 check passed
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.

3 participants