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. Delphi 10.3.3最新消息

    有朋友说,已经开始内测,预计10月末发版,按最新的路线图,此版本支持iOS 13及Android 64位. 2019-11-18,今天,下载及注册机都来了,快下载安装,试用吧. 需要的话加入QQ群20 ...

  2. dedecms:限制栏目列表生成的最大页数防止被采集

    dedecms:限制栏目列表生成的最大页数防止被采集 如果您的网站数据量较大,列表很多的话甚至达到上千页,生成列表时就特别耗费时间,这个缺点可以被优化掉:网站好不容易建起来,担心网站内容被采集走,如果 ...

  3. asp.net 设计音乐网站

    第一步 收集资料 http://www.logoko.com.cn/    --设计logo网站 设计音乐文档  https://wenku.baidu.com/view/3d957617f18583 ...

  4. session传值取值

    protected void Page_Load(object sender, EventArgs e) { //判断session是否为空 if (Session["user"] ...

  5. 少有人知的 GitHub 使用技巧

    GitHub 大家常上吧?可是使用 GitHub 的各种小窍门你就不一定知道了.本文将各种使用 GitHub 的小窍门分享给大家. diff时忽略空格 有些修改只是增减了空格,在URL中添加?w=1就 ...

  6. [转载]springboot--常用注解--@configration、@Bean

    springboot--常用注解--@configration.@Bean @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME ...

  7. ibatis查询列表跟总记录,都引用相同SQL

    在查询记录集合跟查询记录总记录数的时候,我们需要所写的SQL要一样,那么可以都引用同一个SQL.写法如下: <sqlMap namespace="Server"> &l ...

  8. Python JSON Ⅱ

    json.loads json.loads 用于解码 JSON 数据.该函数返回 Python 字段的数据类型. 语法 实例 以下实例展示了Python 如何解码 JSON 对象: 以上代码执行结果为 ...

  9. luogu P2585 [ZJOI2006]三色二叉树

    P2585 [ZJOI2006]三色二叉树 题目描述 输入输出格式 输入格式: 输入文件名:TRO.IN 输入文件仅有一行,不超过10000个字符,表示一个二叉树序列. 输出格式: 输出文件名:TRO ...

  10. 【线性代数】2-6:三角矩阵( $A=LU$ and $A=LDU$ )

    title: [线性代数]2-6:三角矩阵( A=LUA=LUA=LU and A=LDUA=LDUA=LDU ) toc: true categories: Mathematic Linear Al ...