LeetCode 660 Remove 9 (LeetCode Weekly Contest 45)
来源:互联网 发布:网络上关于兄弟的歌曲 编辑:程序博客网 时间:2024/06/07 07:57
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: 9Output: 10
Hint: n will not exceed 9 x 10^8
.
直接把n从十进制转换成九进制,但是要用int来表示这个九进制的数。
class Solution {public: int newInteger(int n) { stack<int> s; int cnt = 0, ret = 0; while (n > 0) { int tmp = n % 9; s.push(tmp); ++cnt; n = n / 9; } int mul = 1; while (--cnt) mul *= 10; while (!s.empty()) { int tmp = s.top(); s.pop(); ret = ret + tmp * mul; mul /= 10; } return ret; }};
阅读全文
0 0
- LeetCode 660 Remove 9 (LeetCode Weekly Contest 45)
- LeetCode Weekly Contest 25
- leetcode weekly contest #26
- leetcode weekly contest #27
- LeetCode Weekly Contest 28
- LeetCode Weekly Contest 30
- LeetCode Weekly Contest 39
- LeetCode Weekly Contest 47
- LeetCode Weekly Contest 51
- LeetCode Weekly Contest 51
- LeetCode Weekly Contest 64
- LeetCode Weekly Contest 45解题思路
- LeetCode Weekly Contest 9 第九周周赛
- leetcode weekly contest 4,3
- LeetCode Weekly Contest 40(1)
- LeetCode Weekly Contest 40(2)
- LeetCode Weekly Contest 40(3)
- LeetCode Weekly Contest 40(4)
- 错误页面不暴漏,显示到一个漂亮页面
- 图像处理与matlab实例之图像平滑(一)
- Apache 配置CGI脚本操作数据库之Perl操作
- codeforces839B(88/600)
- 面向大型集群的简化数据处理(转)
- LeetCode 660 Remove 9 (LeetCode Weekly Contest 45)
- Informatica基础系列(一)——Helloworld
- PyCharm装不了pywin32的解决办法
- JVM中的锁
- 标识符
- Android Kotlin —— 语言结合
- C 指针
- jdk卸载后,重新配置,启动eclipse报错
- Linux字符设备驱动开发基础