JAVA_Prime Number of Set Bits in Binary Representation_LeetCode 762 풀이 class Solution { public int countPrimeSetBits(int left, int right) { int count = 0; for (int i = left; i <= right; i++) if (isPrime(getCnt(i))) count++; return count; } static int getCnt(int n) { int count = 0; while (n > 0) { count++; n -= n & (-n); } return count; } static boolean isPrime(int n) { if (n <= 1) return false; int c = 2; while (c * c <= n) { if (n % c == 0) return false; c++; } return true; } } * 출처 Prime Numbe...
#JAVA
#JAVA_LeetCode762
#JAVA_PrimeNumberofSetBitsinBinaryRepresentation
#JAVA_PrimeNumberofSetBitsinBinaryRepresentation_LeetCode762
#PrimeNumberofSetBitsinBinaryRepresentation_LeetCode762
원문링크 : JAVA_Prime Number of Set Bits in Binary Representation_LeetCode 762