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分钟 ...
随机推荐
- python的基本运算符
目录 基本运算符 1.算术运算符 2.比较运算符 3.赋值运算符 4.逻辑运算符 5.身份运算符 6.位运算符 7.成员运算符 基本运算符 1.算术运算符 运算符 描述 实例 + 加-两个对象相加 a ...
- 注册 Amazon Web Services(AWS) 账号,助园一臂之力
感谢大家去年的大力支持,今年园子继续和 Amazon Web Services(AWS) 合作,只要您通过 博客园专属链接 注册一个账号(建议使用手机4G网络注册),亚马逊就会给园子收入,期待您的支持 ...
- 学习了解使用docker
学习了解使用docker docker是项目开发部署相关工具容器,本文通过官网等资料阅读学习,简单介绍一些基本使用操作: docker是什么 2.docker安装使用 连接进入docker容器 doc ...
- linux开启FTP服务
目录 打开FTP服务 客户端链接时会出现的问题 打开FTP服务 先ping,查看网络是否联通 打开ssh服务 查看一些服务的状态 #查看ssh状态 service sshd status #防火墙的状 ...
- 《Selenium自动化测试实战》新书上市,有需要朋友们可以了解下,欢迎大家多提宝贵意见
京东:https://item.jd.com/13123910.html当当:http://product.dangdang.com/29204520.html 1. 本书基于 Python 3.8 ...
- SpringMVC-02 第一个SpringMVC程序
SpringMVC-02 第一个SpringMVC程序 第一个SpringMVC程序 配置版 新建一个Moudle , springmvc-02-hello,确定依赖导入进去了 1.配置web.xml ...
- Oracle数据库搬家牵扯出的一些知识点记录
Oracle数据库迁移过程中的一些记录 工作原因,对开发服务器的数据库进行了迁移,实际执行操作之前查了一下迁移oracle数据库的可行方案,最后用了 exp/imp 进行导出导入(这个比较简单),以及 ...
- Apache配置 1. 默认虚拟主机
编辑httpd.conf搜索httpd-vhosts,去掉#号 # vi /usr/local/apache2.4/conf/httpd.conf Include conf/extra/httpd-v ...
- Spring如何解决循环依赖
一.什么是循环依赖 多个bean之间相互依赖,形成了一个闭环. 比如:A依赖于B.B依赖于c.c依赖于A 通常来说,如果问spring容器内部如何解决循环依赖, 一定是指默认的单例Bean中,属性互相 ...
- [NOIP 2020] 微信步数
一.题目 点此看题 二.题目 首先感谢一下这位大佬的博客,虽然我看不懂您的讲解,但是还是读得懂代码的 思路是 \(\tt jys\) 给我讲明白的,首先我们可以感觉到快速计算它肯定和矩形有关系,也就是 ...