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
trueif 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: trueExample 2:
Input: 10
Output: falseExample 3:
Input: 16
Output: trueExample 4:
Input: 24
Output: falseExample 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
869. Reordered Power of 2的更多相关文章
- LC 869. Reordered Power of 2
Starting with a positive integer N, we reorder the digits in any order (including the original order ...
- 【LeetCode】869. Reordered Power of 2 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计每位数字出现的次数 日期 题目地址:http ...
- leetcode 869. Reordered Power of 2
function reorderedPowerOf2(N) { var a1 = N.toString().split('') a1.sort((a, b) => a.localeCompare ...
- [LeetCode] Reordered Power of 2 重新排序为2的倍数
Starting with a positive integer N, we reorder the digits in any order (including the original order ...
- [Swift]LeetCode869. 重新排序得到 2 的幂 | Reordered Power of 2
Starting with a positive integer N, we reorder the digits in any order (including the original order ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- 【LeetCode】数学(共106题)
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...
- 【Leetcode周赛】从contest-91开始。(一般是10个contest写一篇文章)
Contest 91 (2018年10月24日,周三) 链接:https://leetcode.com/contest/weekly-contest-91/ 模拟比赛情况记录:第一题柠檬摊的那题6分钟 ...
随机推荐
- 使用syncthing和蒲公英异地组网零成本实现多设备实时同步
设想一个场景,如果两台电脑之间可以共享一个文件夹,其中一个增删更改其中的内容时,另一个也能同步更新,而且速度不能太慢,最好是免费的.那么syncthing就可以满足这个要求.syncthing可以实现 ...
- 基于 vagrant搭建移动端的开发环境
# 后端开发环境Homestead启动 Homestead 之前,确保 VirtualBox .Vagrant.Git 软件己安装. ## 安装 laravel/homesteadvagrant bo ...
- golang——net/rpc包学习
1.rpc包 rpc包提供了通过网络或其他I/O连接对一个对象的导出方法的访问. 只有满足如下标准的方法才能用于远程访问,其余方法会被忽略: (1)方法是导出的(2)方法有两个参数,都是导出类型或内建 ...
- Python接口测试-保持登录状态
#coding:utf-8import requestsimport json#登录url ="https://passport.cnblogs.com/user/signin"h ...
- 写个锤子JS!它应该是你最后的选择
本文翻译自:https://dev.to/olpeh/javascript-should-be-your-last-resort-5dje 在进行现代化Web前端开发时,使用着自己最爱的框架,有时候可 ...
- mysql操作和详解
温馨提示 mysql安装包里面:mysqld是服务端,mysql是客户端. mysqld其实是SQL后台程序(也就是MySQL服务器),它是关于服务器端的一个程序,mysqld意思是mysql dae ...
- Lombok 常用注解总结
本文转载自知乎专栏 极乐科技.有所整理. 主要注解 @Data @Setter @Getter @Log4j @AllArgsConstructor @NoArgsConstructor @Equal ...
- 事件 on
$(选择器).on(事件名称,事件的处理函数) 事件名称:js事件去掉on的部分,例如js中onclick,这里就是click 例如:<input type="button" ...
- A Color Game
题目大意: 给定一个只包含七种字母的字符串,如果满足一段连续相同的字符长度大于等于K那么即可消除,问最后能不能变为空字符. 题解:很明显是用区间dp来解决,我们设dp[l][r][k]代表的是在[l ...
- node_exporter自定义监控
背景 我们在使用Zabbix的时候,可以自己写自定义脚本.在使用Promethues的时候,有很多的exporter,但是有一些特殊的情况没有,比如,我需要监控进程一启动就告警,但是进程没启动,是使用 ...