这是悦乐书的第311次更新,第332篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第180题(顺位题号是762).给定两个正整数L和R,在[L,R]范围内,计算每个整数的二进制数中1的个数,判断1的个数是否是一个素数.例如,21的二进制数是10101,其中1的个数有3个,3是一个素数.例如: 输入:L = 6,R = 10 输出:4 说明: 6 --> 110(2个1,2是素数) 7 --> 111(3个1,3是素数) 9 --> 1001(2个1,2是素数…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历数字+质数判断 日期 题目地址:https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/description/ 题目描述 Given two integers L and R, find the count of numbers in the…
problem 762. Prime Number of Set Bits in Binary Representation solution1: class Solution { public: int countPrimeSetBits(int L, int R) { int res = 0; int bits = 0; for(int i=L; i<=R; i++) { bits = countBits(i); if(isPrime(bits) && bits!=1 ) res…
Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of 1s present when written in bin…
这是悦乐书的第308次更新,第328篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第177题(顺位题号是747).在给定的整数数组中,总有一个最大的元素.查找数组中的最大元素是否至少是数组中每个其他数字的两倍.如果是,则返回最大元素的索引,否则返回-1.例如: 输入:nums = [3,6,1,0] 输出:1 说明:6是最大的整数,对于数组x中的每个其他数字,6是x的两倍多. 值6的索引是1,所以我们返回1. 输入:nums = [1,2,3,4] 输出:-1 说明…
题目要求 Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of 1s present when written i…
Given two integers L and R, find the count of numbers in the range [L, R](inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of 1s present when written in bina…
[抄题]: Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of 1s present when written…
Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of 1s present when written in bin…
思路:动态规划.注意1024*1024>10^6,所以质素范围是(0,23). class Solution { public int countPrimeSetBits(int L, int R) { Set<Integer> prime = new HashSet<Integer>(Arrays.asList(2,3,5,7,11,13,17,19,23)); int[] count = new int[1+R]; int res = 0; for(int i = 1;…