Skip to content

[anniemon78] Week 1 #657

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 4 commits into from
Dec 14, 2024
Merged

[anniemon78] Week 1 #657

merged 4 commits into from
Dec 14, 2024

Conversation

anniemon
Copy link
Contributor

@anniemon anniemon commented Dec 9, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@anniemon anniemon requested a review from y00eunji December 9, 2024 08:11
@anniemon anniemon self-assigned this Dec 9, 2024
@anniemon anniemon requested a review from a team as a code owner December 9, 2024 08:11
@github-actions github-actions bot added the js label Dec 9, 2024
@KwonNayeon KwonNayeon requested review from KwonNayeon and removed request for y00eunji December 13, 2024 01:31
@KwonNayeon
Copy link
Contributor

KwonNayeon commented Dec 13, 2024

안녕하세요! 저는 @anniemon님 바로 전에 PR을 올린 스터디 참가자입니다. 리뷰어 지정이 잘못 되어있는 것 같아서, 제가 임의로 수정하였습니다! 자바스크립트는 처음이지만, 열심히 리뷰해볼게요!

Comment on lines +13 to +23
var containsDuplicate = function(nums) {
const map = new Map();
for(let i = 0; i < nums.length; i++) {
if(!map.has(nums[i])) {
map.set(nums[i], i);
} else {
return true;
}
}
return false;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

안녕하세요! 자바스크립트 언어를 다뤄본 적이 없어서 리뷰를 어떻게 할지 고민하다가, 지피티에게 Python 언어와의 비교를 부탁하여 속성으로 공부해봤습니다. 그 과정에서 Map이 Python의 set과 달리 키-값을 함께 저장한다는 점을 알게 되었는데, 어떤 알고리즘에서 효과적으로 쓰이는지 설명 부탁드려도 될까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

안녕하세요. 공부까지 하셨다니 감사드려요!
자바스크립트의 Map은 기본적으로 해시 테이블이라서, 파이썬에서는 딕셔너리랑 비슷한 걸로 알고 있어요.
따라서 키-밸류를 기반으로 조회/삽입 등이 필요한 경우 사용하므로, 특정 알고리즘에 국한되기보다 광범위하게 사용되는 걸로 알고 있습니다:)

Copy link
Contributor

@KwonNayeon KwonNayeon Dec 14, 2024

Choose a reason for hiding this comment

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

자세한 답변 감사합니다! 리뷰하면서 공부가 많이 되었어요 👍

Comment on lines +14 to +24
var topKFrequent = function(nums, k) {
const map = new Map();
for(const n of nums) {
if(!map.has(n)) {
map.set(n, 0);
}
map.set(n, map.get(n) + 1)
}
const sorted = Array.from(map).sort((a, b) => b[1]-a[1]);
return sorted.slice(0, k).map(e => e[0])
};
Copy link
Contributor

Choose a reason for hiding this comment

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

이 문제를 리뷰하면서 파이썬에서는 key-value를 다룰 때 dictionary를 사용하는데, 자바스크립트에서는 Map이 그 역할을 한다는 걸 알게 됐습니다. 또, if문 안에서 값을 초기화하는 방식이 조금 생소하게 느껴졌어요. 파이썬에서는 보통 defaultdict를 사용해서 초기화를 미리 처리하잖아요. @anniemon님 코드를 리뷰하면서 자바스크립트에 대해 조금 더 알게 되었습니다!

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 +1 to +11
/**
* 시간 복잡도:
* set의 요소 중 연속하는 시퀀스의 첫번째 숫자일 때만
* while 루프를 실행
* 따라서 요소당 최대 1회 순회
* 즉, 시간 복잡도는 O(n)
* 공간 복잡도:
* set은 중복이 없을 경우 최대 O(n)를 차지함
* 즉, 공간 복잡도는 O(n)
*/
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

문제마다 시간/공간 복잡도에 대해 자세히 설명해주셔서 이해하기 쉬웠습니다!

Comment on lines +12 to +34
var isPalindrome = function(s) {
const isAlphaNumeric = (v) => {
return (/^[a-z0-9]$/i).test(v);
};

let l = 0;
let r = s.length - 1;
while(l < r) {
while(!isAlphaNumeric(s[l]) && l < r) {
l++;
}
while(!isAlphaNumeric(s[r]) && l < r) {
r--;
}

if(s[l].toLowerCase() !== s[r].toLowerCase()) {
return false;
}
l++;
r--;
}
return true;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

코드를 완전히 이해하지는 못했지만, @anniemon님의 코드를 보고 저도 공간 효율성을 높이기 위해 투 포인터 방식으로 문제를 다시 풀어봐야겠다는 아이디어를 얻었습니다! 감사합니다 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

성의 있는 리뷰 감사드려요! 화이팅입니다:)

@anniemon anniemon merged commit aff647b into DaleStudy:main Dec 14, 2024
1 check 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