Start from integer 1, remove any integer that contains 9 such as 9, 19, 29...

So now, you will have a new integer sequence: 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...

Given a positive integer n, you need to return the n-th integer after removing. Note that 1 will be the first integer.

Example 1:

Input: 9
Output: 10

Hint: n will not exceed 9 x 10^8.

找规律题。借鉴网上的思路。

1,2,3,4,5,6,7,8,10,。。。,18,20,。。。28,30

把9拿掉以后,可以把它看成一个九进制的序列。也就是说,9进制中的数字n如果把它当作10进制来看,就是在这个序列中的第n个。

class Solution {
public:
int newInteger(int n) {
int base = ;
int ans = ;
while(n != ){
ans = ans + (n % ) * base;
n /= ;
base *= ;
}
return ans;
}
};

最新文章

  1. GJM : Unity3D HIAR -【 快速入门 】 六、导出 iOS 工程
  2. C#微信公众号开发系列教程三(消息体签名及加解密)
  3. xampp下创建多个虚拟网站目录
  4. ASP.NET Web API涉及到的上下文
  5. lucene 建立索引的过程
  6. Amoeba基本配置
  7. C#之使用随机数
  8. Delphi 6 Web Services初步评估
  9. App列表之分组ListView
  10. xsd的解释说明
  11. Bug(案例)图片的垂直出现隐藏
  12. .net SignalR winform 推送广播
  13. 大名鼎鼎的红黑树,你get了么?2-3树 绝对平衡 右旋转 左旋转 颜色反转
  14. c语言编译四大步
  15. JavaScript 是如何工作:Shadow DOM 的内部结构 + 如何编写独立的组件!
  16. noip第17课资料
  17. 【转帖】intel 2018年1 月2号爆出漏洞分析 知乎匿名用户
  18. c++-pimer-plus-6th-chapter03
  19. 《Google Glass开发指南》
  20. Logback中文文档(二):体系结构

热门文章

  1. mybatis框架中 #和$传递参数的区别 和注意
  2. python3.6 错误: ModuleNotFoundError:No module named "Crypto"
  3. Oracle11g adump目录下面.aud增长导致空间撑满无法删除导致CRS无法启动的解决方法
  4. 流媒体服务器搭建 red5
  5. CSS基础学习-4.CSS属性_背景、颜色、边框
  6. Java程序中使用 Jsoup 爬虫( 简单示例 )
  7. 虚拟机vmware的连接方式以及IP端口,协议等概念
  8. mongodb添加索引
  9. java 和 c#返回值方法
  10. 【原】涉及数据库的单元测试-JTeser