当前位置:网站首页>leetcode 869. Reordered Power of 2 | 869. Reorder to a power of 2 (state compression)
leetcode 869. Reordered Power of 2 | 869. Reorder to a power of 2 (state compression)
2022-07-08 02:03:00 【Cold spring HQ】
subject
https://leetcode.com/problems/reordered-power-of-2/
Answer key
class Solution {
public boolean reorderedPowerOf2(int n) {
Set<Long> set = new HashSet<>();
int target = 1;
for (int i = 0; i < 31; i++) {
set.add(compress(target));
target <<= 1;
}
return set.contains(compress(n));
}
public long compress(int n) {
// int Pai Pingcheng array
// index 0 1 2 3 4 5 6 7 8 9
// num=2566 -> [0,0,1,0,0,1,2,0,0,0]
int[] count = new int[10];
for (char c : String.valueOf(n).toCharArray()) {
count[c - '0']++;
}
// Yes array State compression
// [0,0,1,0,0,1,2,0,0,0] -> 0010012000
long res = 0;
for (int c : count) {
res *= 10;
res += c;
}
return res;
}
}

边栏推荐
- Cross modal semantic association alignment retrieval - image text matching
- C语言-模块化-Clion(静态库,动态库)使用
- 发现值守设备被攻击后分析思路
- Wechat applet uniapp page cannot jump: "navigateto:fail can not navigateto a tabbar page“
- Can you write the software test questions?
- nmap工具介紹及常用命令
- JVM memory and garbage collection-3-object instantiation and memory layout
- Why did MySQL query not go to the index? This article will give you a comprehensive analysis
- Clickhouse principle analysis and application practice "reading notes (8)
- Optimization of ecological | Lake Warehouse Integration: gbase 8A MPP + xeos
猜你喜欢

Nanny level tutorial: Azkaban executes jar package (with test samples and results)
Can you write the software test questions?

C语言-模块化-Clion(静态库,动态库)使用

云原生应用开发之 gRPC 入门

JVM memory and garbage collection-3-direct memory
![[SolidWorks] modify the drawing format](/img/3c/b00e4510b1e129069140c2666c0727.png)
[SolidWorks] modify the drawing format

Nmap tool introduction and common commands

Nacos microservice gateway component +swagger2 interface generation

Ml self realization / logistic regression / binary classification

关于TXE和TC标志位的小知识
随机推荐
QML fonts use pixelsize to adapt to the interface
如何用Diffusion models做interpolation插值任务?——原理解析和代码实战
cv2-drawline
metasploit
In depth analysis of ArrayList source code, from the most basic capacity expansion principle, to the magic iterator and fast fail mechanism, you have everything you want!!!
Installing and using mpi4py
JVM memory and garbage collection-3-runtime data area / method area
Redission源码解析
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
数据链路层及网络层协议要点
Redisson分布式锁解锁异常
静态路由配置全面详解,静态路由快速入门指南
Why did MySQL query not go to the index? This article will give you a comprehensive analysis
Le chemin du poisson et des crevettes
阿南的判断
If time is a river
WPF custom realistic wind radar chart control
cv2-drawline
Many friends don't know the underlying principle of ORM framework very well. No, glacier will take you 10 minutes to hand roll a minimalist ORM framework (collect it quickly)
List of top ten domestic industrial 3D visual guidance enterprises in 2022