LC 660. Remove 9 【lock, hard】
2024-09-25 01:35:15
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;
}
};
最新文章
- GJM : Unity3D HIAR -【 快速入门 】 六、导出 iOS 工程
- C#微信公众号开发系列教程三(消息体签名及加解密)
- xampp下创建多个虚拟网站目录
- ASP.NET Web API涉及到的上下文
- lucene 建立索引的过程
- Amoeba基本配置
- C#之使用随机数
- Delphi 6 Web Services初步评估
- App列表之分组ListView
- xsd的解释说明
- Bug(案例)图片的垂直出现隐藏
- .net SignalR winform 推送广播
- 大名鼎鼎的红黑树,你get了么?2-3树 绝对平衡 右旋转 左旋转 颜色反转
- c语言编译四大步
- JavaScript 是如何工作:Shadow DOM 的内部结构 + 如何编写独立的组件!
- noip第17课资料
- 【转帖】intel 2018年1 月2号爆出漏洞分析 知乎匿名用户
- c++-pimer-plus-6th-chapter03
- 《Google Glass开发指南》
- Logback中文文档(二):体系结构
热门文章
- mybatis框架中 #和$传递参数的区别 和注意
- python3.6 错误: ModuleNotFoundError:No module named ";Crypto";
- Oracle11g adump目录下面.aud增长导致空间撑满无法删除导致CRS无法启动的解决方法
- 流媒体服务器搭建 red5
- CSS基础学习-4.CSS属性_背景、颜色、边框
- Java程序中使用 Jsoup 爬虫( 简单示例 )
- 虚拟机vmware的连接方式以及IP端口,协议等概念
- mongodb添加索引
- java 和 c#返回值方法
- 【原】涉及数据库的单元测试-JTeser