LeetCode 5108. Encode Number - Java - 2进制
2024-09-01 00:01:09
题目链接:https://leetcode-cn.com/problems/encode-number/
Given a non-negative integer num
, Return its encoding string. @wowpH
The encoding is done by converting the integer to a string using a secret function that you should deduce from the following table:
Example 1:
Input: num = 23
Output: "1000"
Example 2:
Input: num = 107
Output: "101100"
Constraints:
0 <= num <= 10^9
题解
f(n) | 前面加"1" | 10进制 | n |
---|---|---|---|
"" | "1" | 1 | 0 |
"0" | "10" | 2 | 1 |
"1" | "11" | 3 | 2 |
"00" | "100" | 4 | 3 |
"01" | "101" | 5 | 4 |
"10" | "110" | 6 | 5 |
"11" | "111" | 7 | 6 |
"000" | "1000" | 8 | 7 |
Java代码
class Solution {
public String encode(int num) {
return Integer.toBinaryString(num + 1).substring(1);
}
}
原文链接:https://www.cnblogs.com/wowpH/p/11880529.html
- wowpH -
最新文章
- T-SQL:毕业生出门需知系列(四)
- CF444C. DZY Loves Colors[线段树 区间]
- jdbctemplate中的批量更新使用,BigDecimal与造型的联系和区别
- (八)Hibernate 映射关系
- 《Numerical Methods》-chaper4-一元非线性方程的解
- highCharts 图表统计控件使用方法
- [LeetCode 111] - 二叉树的最小深度 (Minimum Depth of Binary Tree)
- c# 输出excel、word实例只需一行代码
- ContentProvider中的数据生成时机
- windows xp sp3 下载地址
- 史上最全的IntelliJIdea快捷键
- Beta冲刺第二天
- 【实验吧】CTF_Web_简单的SQL注入之1
- Feature Extractor[googlenet v1]
- Fluent动网格【12】:扩散光顺
- 聊聊大麦网UWP版的首页顶部图片联动效果的实现方法
- 关于vue里页面的缓存
- vs 加载 dll 缓慢
- 算法生成N芒星
- Linux文本编辑器(九)
热门文章
- 使用packer 打包nodegui 应用
- 系统权限划分Liunx版
- 将两个各有n个元素的有序表归并成一个有序表,其最多的比较次数
- 记一次CPU使用100%问题排查
- [sdoi 2017]树点涂色
- [Gamma阶段]第二次Scrum Meeting
- SEAndroid
- 使用Rome读取RSS报错,org.xml.sax.SAXParseException: 前言中不允许有内容。
- Microsoft.Owin 使用 文件服务
- [转][c++]关于构造函数不能有返回类型的错误