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
 
Runtime: 11 ms, faster than 52.38% of Java online submissions for Reordered Power of 2.
class Solution {
private char[] Ncarr;
public boolean ispermutation(String astr){
char[] acarr = astr.toCharArray();
Arrays.sort(acarr);
for(int i=; i<acarr.length; i++){
if(acarr[i] != Ncarr[i]) return false;
}
return true;
} public boolean reorderedPowerOf2(int N) {
if(N == || N == ) return true;
String Nstr = Integer.toString(N);
Ncarr = Nstr.toCharArray();
Arrays.sort(Ncarr);
int digitN = Nstr.length();
int base = ;
List<String> tmplist = new ArrayList<>();
while(true){
String tmp = Integer.toString(base);
if(tmp.length() == digitN) tmplist.add(tmp);
if(((base >> ) & ) == ) break;
if(tmp.length() > digitN) break;
base <<= ;
}
for(String x : tmplist){
if(ispermutation(x)) return true;
}
return false;
} }
 

LC 869. Reordered Power of 2的更多相关文章

  1. 869. Reordered Power of 2

    Starting with a positive integer N, we reorder the digits in any order (including the original order ...

  2. 【LeetCode】869. Reordered Power of 2 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计每位数字出现的次数 日期 题目地址:http ...

  3. leetcode 869. Reordered Power of 2

    function reorderedPowerOf2(N) { var a1 = N.toString().split('') a1.sort((a, b) => a.localeCompare ...

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

    Starting with a positive integer N, we reorder the digits in any order (including the original order ...

  5. lc面试准备:Power of Two

    1 题目 Given an integer, write a function to determine if it is a power of two. 接口 boolean isPowerOfTw ...

  6. [Swift]LeetCode869. 重新排序得到 2 的幂 | Reordered Power of 2

    Starting with a positive integer N, we reorder the digits in any order (including the original order ...

  7. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

  8. 【Leetcode周赛】从contest-91开始。(一般是10个contest写一篇文章)

    Contest 91 (2018年10月24日,周三) 链接:https://leetcode.com/contest/weekly-contest-91/ 模拟比赛情况记录:第一题柠檬摊的那题6分钟 ...

  9. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

随机推荐

  1. JPA的API介绍、工具类抽取

    1.Persistence对象 Persistence对象主要作用是用于获取EntityManagerFactory对象的 .通过调用该类的createEntityManagerFactory静态方法 ...

  2. Delphi 类的特性

  3. JAVA中AES对称加密和解密以及与Python兼容

    引言:本文主要解决Java中用AES加密及解密,同时可通过Python脚本对Java加密后的字符进行解密的操作. 由于近期工作中用到需要使用Java对一串密钥进行加密,并且后台通过Python语言读取 ...

  4. 自定义ViewGroup基础巩固2---onMeasure()学习及综合实现圆形菜单

    上次对自定义ViewGroup中的onLayout()方法进行了基础巩固[http://www.cnblogs.com/webor2006/p/7507284.html],对于熟知自定义ViewGro ...

  5. 一个restframework快速实例

    首先在settings.py中引入 INSTALLED_APPS = [ ...... 'rest_framework', ......] 相关模型结构如下: class custume(models ...

  6. jquery里把数组转换成json的方法

    首先来看,jquery里自带的,和json相关的函数: 1.$.parseJSON  :  用来解析JSON字符串,返回一个对象. 什么叫“JSON字符串”? 比如: var a={name:&quo ...

  7. mysql优化之SQL优化

    https://www.cnblogs.com/binghou/p/9096610.html (SQL优化)

  8. Appium Python核心API

    adb命令模拟按键事件 :http://blog.sina.com.cn/s/blog_68f262210102vc1b.html

  9. PHP mysqli_kill() 函数

    定义和用法 mysqli_kill() 函数请求服务器杀死一个由 processid 参数指定的 MySQL 线程. 语法 mysqli_kill(connection,processid);   实 ...

  10. 013_linuxC++之_派生类中权限的调整

    (一)在上一篇012_LINUXC++之_类的继承定义中我们知道在派生类中可以访问public和protectd中的数据 (二)那么我们就可以在派生类中将上面两个中的数据进行权限的修改 (三)程序 # ...