[LeetCode] Reordered Power of 2 重新排序为2的倍数

Starting with a positive integer?N, we reorder the digits in any order (including the original order) such that the leading digit is not zero.

Return?true?if and only if we can do this in a way such that the resulting number is a power of 2.

Example 1:

Input: 1
Output: true

Example 2:

Input: 10
Output: false

Example 3:

Input: 16
Output: true

Example 4:

Input: 24
Output: false

Example 5:

Input: 46
Output: true

Note:

  1. 1 <= N <= 10^9

参考资料:

https://leetcode.com/problems/reordered-power-of-2/

LeetCode All in One 题目讲解汇总(持续更新中...)

原文地址:https://www.cnblogs.com/grandyang/p/10747839.html

时间: 2024-10-15 22:26:10

[LeetCode] Reordered Power of 2 重新排序为2的倍数的相关文章

LeetCode 231 Power of Two(2的幂)

翻译 给定一个整型数,写一个函数来决定它是否是2的幂. 原文 Given an integer, write a function to determine if it is a power of two. 分析 详情请看这篇文章:LeetCode 326 Power of Three(3的幂)(递归.Log函数) 看题号,326是本题的加强版,326是要求不能用循环或递归的--大家可以去看看上面那篇文章. 本题就直接贴我的代码了-- 代码 class Solution { public: bo

[Math_Medium] 869. Reordered Power of 2

原题:869. Reordered Power of 2 Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting num

[LeetCode][JavaScript]Power of Three

Power of Three Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion? https://leetcode.com/problems/power-of-three/ 要求判断一个数是不是3的幂次方. 最直观的做法是不停除以3,看余数是否为零. 题目要求不能用递归和循环,

【Leetcode】Power of Four

题目链接:https://leetcode.com/problems/power-of-four/ 题目: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it without lo

[LeetCode][JavaScript]Power of Two

Power of Two Given an integer, write a function to determine if it is a power of two. https://leetcode.com/problems/power-of-two/ 二分. 2的整数次幂,要么开方后是整数(这个数也是2的整数次幂),要么除以2之后再开方后是整数.继续递归判断开方后的结果直到碰到1或者2. 比如1024(2^10),是由两个32(2^5)相乘:2048(2^11),是由两个32(2^5)相

869. Reordered Power of 2

Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2. Example

leetcode 231. Power of Two

Given an integer, write a function to determine if it is a power of two. class Solution { public: bool isPowerOfTwo(int n) { int num = 0; while (n > 0) { if (n &1) num++; n/=2; } if (num == 1) return true; return false; } };

39. leetcode 326. Power of Three

326. Power of Three Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? 思路:看这个数取以3为底的对数结果是否为整数,C++中只有自然对数函数log()和以10为底的对数函数log10(),所以要借助换底公式.此处用自然对数会有精度问题,用以10为底的对数

LeetCode 342. Power of Four

Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it without loops/recursion? 先说明用循环: 如下 class Solution { public: bool