869. Reordered Power of 2
of POWER
2023-09-11 14:22:44 时间
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 <= N <= 10^9
Approach #1: Math. [Java]
class Solution { public boolean reorderedPowerOf2(int N) { int c = count(N); for (int i = 0; i < 32; ++i) { if (count(1 << i) == c) return true; } return false; } public int count(int x) { int ret = 0; for (; x > 0; x /= 10) ret += (int)Math.pow(10, x % 10); return ret; } }
Analysis:
The way that use / and % to count the digit is awesome.
Reference:
https://leetcode.com/problems/reordered-power-of-2/discuss/149843/C%2B%2BJavaPython-Straight-Forward
相关文章
- ZOJ Problem Set - 3708 Density of Power Network
- [Javascript] Use an Array of Promises with a For Await Of Loop
- 论文阅读:Review of Visual Saliency Detection with Comprehensive Information
- (纪录片)科学的故事:权力、证据与激情 The Story Of Science: Power, Proof And Passion
- flutter:处理报错:Unimplemented handling of missing static target(flutter 3.7.0)
- 【codeforces 777D】Cloud of Hashtags
- AI:Algorithmia《2020 state of enterprise machine learning—2020年企业机器学习状况》翻译与解读
- 成功解决pandascoregeneric.py:3660: SettingWithCopyWarning: A value is trying to be set on a copy of a
- LVLG 8.2 circular scrolling animation of a label
- container_of宏剖析
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type '' available: expected at least 1 bean which qualifies as autowire candidate.
- leetcode 231. Power of Two
- 【文献学习】2 Power of Deep Learning for Channel Estimation and Signal Detection in OFDM
- 论文阅读《The Funny Thing About Incongruity: A Computational Model of Humor in Puns》
- springboot启动报错Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary
- MySQL报错Column count of mysql.user is wrong. Expected 43, found 42. Created with MySQL 50568, now run