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分钟 ...
随机推荐
- Java基本概念:内部类
一.简介 描述: 很多时候我们创建类的对象的时候并不需要使用很多次,每次只使用一次,这个时候我们就可以使用内部类了. 内部类不是在一个java源文件中编写两个平行的类,而是在一个类的内部再定义另外一个 ...
- PHP Webshell List
目录 基础类 编码替换 无关键字函数类型 躲避检测记录 MySQL写入一句话 基础类 很容易被扫描.检测出来 <?php @eval($_GET['phpcode']);?> <?p ...
- Mybatis系列全解(二):Mybatis简介与环境搭建
封面:洛小汐 作者:潘潘 Mybatis 是一套持久层框架,灵活易用,特别流行. 前言 Mybatis系列全解,我们预计准备10+篇文章,让我们了解到 Mybatis 的基本全貌,真正从入门到上手,从 ...
- 基于Hi3559AV100 RFCN实现细节解析-(3)系统输入VI分析一 :
下面随笔系列将对Hi3559AV100 RFCN实现细节进行解析,整个过程涉及到VI.VDEC.VPSS.VGS.VO.NNIE,其中涉及的内容,大家可以参考之前我写的博客: Hi3559AV100的 ...
- Codeforces Round #683 (Div. 2, by Meet IT)
A 初始情况\(1\) ~ \(n\)堆分别有 \(1\) ~ \(n\) 个糖果,第\(i\)次操作给除了所选堆的糖果数 \(+ i\), 找到一种方案可以使得所有堆糖果数相同,输出操作次数和每次选 ...
- 什么是ETL?
一.ETL概念之背景 随着企业的发展,目前的业务线越来越复杂,各个业务系统独立运营.例如:CRM系统只会生产CRM的 数据:Billing只会生产Billing的数据.各业务系统之间只关心自己的数据, ...
- css实现京东顶部导航条
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...
- kthread_worker和kthread_work机制
1.概述 在阅读内核源码时,可以看到kthread_worker.kthread_work两个数据结构配合内核线程创建函数一起使用的场景.刚开始看到这块时,比较困惑,紧接着仔细分析源码后,终于弄清楚了 ...
- DNS 缓存中毒--Kaminsky 攻击复现
0x00 搭建实验环境 使用3台Ubuntu 16.04虚拟机,可到下面的参考链接下载 攻击的服务是BIND9,由于条件限制,这里使用本地的一台虚拟机当作远程DNS解析器,关闭了DNSSEC服务,其中 ...
- js--如何实现继承?
前言 学习过 java 的同学应该都知道,常见的继承有接口继承和实现继承,接口继承只需要继承父类的方法签名,实现继承则继承父类的实际的方法,js 中主要依靠原型链来实现继承,无法做接口继承. 学习 j ...