• 문제 링크
Prime Number of Set Bits in Binary Representation - LeetCode
Can you solve this real interview question? Prime Number of Set Bits in Binary Representation - Given two integers left and right, return the count of numbers in the inclusive range [left, right] having a prime number of set bits in their binary representa
leetcode.com
• 풀이 코드
public class Solution {
public int countPrimeSetBits(int left, int right) {
int cnt = 0, mask = 665772;
for (int i = left; i <= right; i++) if ((mask & (1 << Integer.bitCount(i))) != 0) cnt++;
return cnt;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 771. Jewels and Stones - Java (0) | 2026.10.13 |
|---|---|
| [LeetCode] 766. Toeplitz Matrix - Java (0) | 2026.10.12 |
| [LeetCode] 748. Shortest Completing Word - Java (0) | 2026.10.10 |
| [LeetCode] 747. Largest Number At Least Twice of Others - Java (0) | 2026.10.09 |
| [LeetCode] 746. Min Cost Climbing Stairs - Java (0) | 2026.10.08 |
댓글