Skip to content

Conversation

yolophg
Copy link
Contributor

@yolophg yolophg commented May 25, 2024

  • Number of 1 Bits
  • Counting Bits
  • Reverse Bits
  • Missing Number
  • Group Anagrams

}

// convert to unsigned integer.
return result >>> 0;
Copy link
Member

Choose a reason for hiding this comment

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

>>>가 right shift 연산이라면, 0을 해야하는 이유가 있는건지 궁금해요.
이미 result는 양수의 값을 갖고 있으므로 unsigned integer로 만들 것 없이 그냥 반환해도 괜찮지 않을까 생각이 들었거든요.
(JS를 몰라서 제가 예단하고 있는 거겠지만요 ㅎㅎ)
만약 하지 않았을 경우 잘못된 정답이 리턴될 수도 있나요?

const count = new Array(26).fill(0);
// increment the count for each character.
for (const char of str) {
count[char.charCodeAt(0) - 'a'.charCodeAt(0)]++;
Copy link
Contributor

Choose a reason for hiding this comment

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

ASCII 코드를 활용해서 인덱스 값을 주는 방법도 가능하군요!
좋은 접근방법인 것 같습니다.

@SamTheKorean SamTheKorean merged commit 99e7ce5 into DaleStudy:main May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants