LC 660. Remove 9 【lock, hard】
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;
}
};
LC 660. Remove 9 【lock, hard】的更多相关文章
- LC 656. Coin Path 【lock, Hard】
Given an array A (index starts at 1) consisting of N integers: A1, A2, ..., AN and an integer B. The ...
- LC 163. Missing Ranges 【lock, hard】
Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, up ...
- LC 871. Minimum Number of Refueling Stops 【lock, hard】
A car travels from a starting position to a destination which is target miles east of the starting p ...
- LC 425. Word Squares 【lock,hard】
Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...
- LC 759. Employee Free Time 【lock, hard】
We are given a list schedule of employees, which represents the working time for each employee. Each ...
- LC 245. Shortest Word Distance III 【lock, medium】
Given a list of words and two words word1 and word2, return the shortest distance between these two ...
- LC 244. Shortest Word Distance II 【lock, Medium】
Design a class which receives a list of words in the constructor, and implements a method that takes ...
- LC 499. The Maze III 【lock,hard】
There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolli ...
- LC 302. Smallest Rectangle Enclosing Black Pixels【lock, hard】
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
随机推荐
- JavaWeb【二、Tomcat安装】
简版: 下载安装 http://tomcat.apache.org/download-80.cgi 环境变量 CATALINA_HOME-tomcat安装路径-[E:\apache-tomcat-8. ...
- Linux基础命令02
常用的一些命令选项 向网络发送icmp检测主机是否在线 ping 指定发送包数量 ping -c windows系统中是ping -t不间断刷包 比如ping百度,ping不同,一直卡在这里,加了-w ...
- python 3.4.3 安装pygame
之前一直都是用的python3.5,后来接触了pygame,又被python3.5的打包折磨的死去活来,后来干脆用python 3.4.3. 我之前安装轮子都是直接打开cmd,然后 pip3 inst ...
- Web Api(1)
由于在学习Web Api没有了解过MVC,觉得有些吃力.很多基础的东西都会一并记录下来. Web API 的意思是使用HTTP协议并通过网络调用的API. API的意思软件外部接口. 在实际的开发中, ...
- spring cache会默认使用redis作为缓存吗?
web项目中,只需要配置 redis 的IP,端口,用户名和密码就可以使用redis作为缓存了,不需要在在java 代码中配置redisConfig,redisConfig只是作为缓存配置的辅助,比如 ...
- poj3417 Network/闇の連鎖[树上差分]
首先隔断一条树边,不计附加边这个树肯定是断成两块了,然后就看附加边有没有连着的两个点在不同的块内. 方法1:BIT乱搞(个人思路) 假设考虑到$x$节点隔断和他父亲的边,要看$x$子树内有没有点连着附 ...
- React组件:Dragact 0.1.4发布
Dragact 是一款React组件,他能够使你简单.快速的构建出一款强大的 拖拽式网格(grid)布局. 仓库地址:Dragact 经过几天的迭代时间Dragact已经能够支持自由缩放功能了(res ...
- TCP数据段格式+UDP数据段格式详解
TCP 报文格式 TCP(Transmission Control Protocol 传输控制协议)是一种面向连接的.可靠的.基于字节流的传输层通信协议. TCP 报文段的报头有 10 个必需的字段和 ...
- 浮动float和清除clear
一.浮动(float) float简介 取值:left,right,none,inherit,默认none(不浮动) 可应用与所有元素 没有继承性 不在正常流中,但会影响布局.因为一个元素浮动时,其他 ...
- 【Python之路】特别篇--Python反射
反射 说反射之前先介绍一下__import__方法,这个和import导入模块的另一种方式 1. import commons 2. __import__('commons') 如果是多层导入: 1. ...