660. Remove 9(一种难理解的进制转换)
2017-08-22 11:57
267 查看
660. Remove 9
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.
example1:
Input: 9
Output: 10
Hint: n will not exceed 9 x 10^8.
nodes
因为删除的是最后一位9,所以实际上就是10进制转9进制的算法
int newInteger(int n) { int ans = 0; int base = 1; while (n > 0){ ans += n % 9 * base; n /= 9; base *= 10; } return ans; }
相关文章推荐
- 汉诺塔算法-换一种方式去理解
- 矩阵的理解(1)--矩阵是一种运动
- word2vec中一种模型的理解
- [数据库事务与锁]详解八:底理解数据库事务乐观锁的一种实现方式——CAS
- 分治 棋盘覆盖 超级好理解的一种写法!
- 上千篇文章肯定不会全部出现在考试的“阅读理解“中,我们依然要学习千年不变的语文课本,其实就是在学习一种”分析的思维“,一种”举一反三“的能力。
- MFC框架的一种理解方法
- 完成端口的深入理解及一种变态用法
- 理解 Ajax 及其工作原理,构建网站的一种有效方法
- word2vec中一种模型的理解
- 一种方便理解的mysql 去重方法
- 理解Bitcode:一种中间代码
- Mysql一种模拟row_number() over方式及理解
- 一种对拉格朗日乘子的直观理解
- uip(一种MVC模式的实现)模式的理解 -微软提供的框架
- 理解web服务模式(一):应该采用哪一种 WSDL样式?
- ios中kvo的使用,一种类似后门的用法,大家看一看,即使不用也可以加深对kvo的理解
- word2vec中一种模型的理解
- 怎么理解这样一种编程思路
- 完成端口的深入理解及一种变态用法