当前位置:网站首页>leetcode 869. Reordered Power of 2 | 869. 重新排序得到 2 的幂(状态压缩)
leetcode 869. Reordered Power of 2 | 869. 重新排序得到 2 的幂(状态压缩)
2022-07-08 00:37:00 【寒泉Hq】
题目
https://leetcode.com/problems/reordered-power-of-2/
题解
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拍平成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']++;
}
// 对array状态压缩
// [0,0,1,0,0,1,2,0,0,0] -> 0010012000
long res = 0;
for (int c : count) {
res *= 10;
res += c;
}
return res;
}
}
边栏推荐
- Introduction to Microsoft ad super Foundation
- Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
- 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!!!
- Redismission source code analysis
- Optimization of ecological | Lake Warehouse Integration: gbase 8A MPP + xeos
- 快手小程序担保支付php源码封装
- 如何制作企业招聘二维码?
- Application of slip ring in direct drive motor rotor
- Sword finger offer II 041 Average value of sliding window
- From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
猜你喜欢
Clickhouse principle analysis and application practice "reading notes (8)
burpsuite
Version 2.0 of tapdata, the open source live data platform, has been released
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
【目标跟踪】|atom
Redux usage
给刚入门或者准备转行网络工程师的朋友一些建议
See how names are added to namespace STD from cmath file
剑指 Offer II 041. 滑动窗口的平均值
如何制作企业招聘二维码?
随机推荐
How to make enterprise recruitment QR code?
[target tracking] |atom
leetcode 873. Length of Longest Fibonacci Subsequence | 873. 最长的斐波那契子序列的长度
Keras' deep learning practice -- gender classification based on inception V3
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
WPF custom realistic wind radar chart control
Ml self realization / linear regression / multivariable
保姆级教程:Azkaban执行jar包(带测试样例及结果)
[target tracking] |dimp: learning discriminative model prediction for tracking
List of top ten domestic industrial 3D visual guidance enterprises in 2022
Codeforces Round #649 (Div. 2)——A. XXXXX
Introduction to grpc for cloud native application development
Uniapp one click Copy function effect demo (finishing)
《ClickHouse原理解析与应用实践》读书笔记(7)
批次管控如何实现?MES系统给您答案
Redisson分布式锁解锁异常
Why did MySQL query not go to the index? This article will give you a comprehensive analysis
第七章 行为级建模
Is NPDP recognized in China? Look at it and you'll see!
cv2-drawline