题目链接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 -

最新文章

  1. T-SQL:毕业生出门需知系列(四)
  2. CF444C. DZY Loves Colors[线段树 区间]
  3. jdbctemplate中的批量更新使用,BigDecimal与造型的联系和区别
  4. (八)Hibernate 映射关系
  5. 《Numerical Methods》-chaper4-一元非线性方程的解
  6. highCharts 图表统计控件使用方法
  7. [LeetCode 111] - 二叉树的最小深度 (Minimum Depth of Binary Tree)
  8. c# 输出excel、word实例只需一行代码
  9. ContentProvider中的数据生成时机
  10. windows xp sp3 下载地址
  11. 史上最全的IntelliJIdea快捷键
  12. Beta冲刺第二天
  13. 【实验吧】CTF_Web_简单的SQL注入之1
  14. Feature Extractor[googlenet v1]
  15. Fluent动网格【12】:扩散光顺
  16. 聊聊大麦网UWP版的首页顶部图片联动效果的实现方法
  17. 关于vue里页面的缓存
  18. vs 加载 dll 缓慢
  19. 算法生成N芒星
  20. Linux文本编辑器(九)

热门文章

  1. 使用packer 打包nodegui 应用
  2. 系统权限划分Liunx版
  3. 将两个各有n个元素的有序表归并成一个有序表,其最多的比较次数
  4. 记一次CPU使用100%问题排查
  5. [sdoi 2017]树点涂色
  6. [Gamma阶段]第二次Scrum Meeting
  7. SEAndroid
  8. 使用Rome读取RSS报错,org.xml.sax.SAXParseException: 前言中不允许有内容。
  9. Microsoft.Owin 使用 文件服务
  10. [转][c++]关于构造函数不能有返回类型的错误