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】的更多相关文章

  1. 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 ...

  2. LC 163. Missing Ranges 【lock, hard】

    Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, up ...

  3. 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 ...

  4. LC 425. Word Squares 【lock,hard】

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  5. LC 759. Employee Free Time 【lock, hard】

    We are given a list schedule of employees, which represents the working time for each employee. Each ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. SocketClient

    import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.i ...

  2. go语言json转map

    package util import ( "encoding/json" "fmt" ) // json转map函数,通用 func JSONToMap(st ...

  3. 使用tinyproxy进行ip代理

    爬虫经常用到ip代理.解决方案无非几种: 1.网络上寻找一些免费代理,优点:免费不限量:缺点:可用性较低,验证费时间费资源.一些有免费代理的网站,西刺代理,站大爷,89免费代理等等,网上可以搜出一大堆 ...

  4. 查看是否用GPU跑的TensorFlow程序

    查看是否用GPU跑的TensorFlow程序 第一种方法,直接输出日志法(推荐) import tensorflow as tf sess = tf.Session(config=tf.ConfigP ...

  5. Python往kafka生产消费数据

    安装 kafka:  pip install kafka-python 生产数据 from kafka import KafkaProducer import json ''' 生产者demo 向te ...

  6. Hdu 1525 欧几里得博弈

    两堆石子每次可以在大堆中取小堆的倍数个石子 第一个拿光某个堆的玩家赢 假设a>=b 必胜状态:a%b==0或a/b>=2 因为当a/b>=2时 当前玩家可以选择将状态转移至 a%b+ ...

  7. Summer training #2

    A:不管有没有负数 一顿操作之后肯定只有正数 又因为A=A-B 所以最大值是一直在减小的 所以一定有结果 B:..一开始以为求min操作数 WA了2发 直接求所有数的GCD如果所有数的GCD都不是1的 ...

  8. Linux用iso镜像制作本地yum源

    本次使用的软件为RHEL 6.5和VMware Workstation10 挂载iso镜像   (创建挂载目录,再挂载,进入目录查看是否挂载成功) (根据相应情况,镜像文件一般为sr0 我电脑里是第二 ...

  9. zeromq实践

    zeromq简介 zeroMQ不是TCP,不是socket,也不是消息队列,而是这些的综合体. ZeroMQ以嵌入式网络编程库的形式实现了一个并行开发框架(concurrency framework) ...

  10. 函数参数-arguments-reset参数

    1.JS中用:arguments 1)存放实参的集合,是一个类似于数组的对象,只有数组的 length,没有数组方法 function add1(a,b,c) { console.log(argume ...