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 ...
随机推荐
- python网络编程:TCP通讯模板、粘包及解决方案、自定义报头
一.TCP通讯模板 二.远程CMD程序 三.解决粘包问题 四.解决粘包问题2 一.TCP通讯模板 TCP客户端 import socket c = socket.socket() # 连接服务器 c. ...
- Tomcat7设置环境变量供java代码读取
前两天要做一个后台线程分片处理任务功能,把应用放在tomcat中部署在多个服务器上,每个服务器分片处理一些任务,这里需要在java代码中获取到tomcat的信息和服务器信息.在网上找了好久,终于找到了 ...
- 51Nod 1534 棋盘阻挡博弈
很简单的可以知道 如果P在V的右上角 必输 如果P在V的左下角 必赢 接下里还剩下左上角和右下角两种情况 两种情况其实相同 P是挡不住V通过对角线方向向下/左的移动的 即两者不会相互影响 所以我们只要 ...
- 使用IDA Pro逆向C++程序
使用IDA Pro逆向C++程序 附:中科院李_硕博 : IDA用来做二进制分析还是很强大的 .lib程序是不是很容易分析出源码? 这个得看编译选项是怎么设置的 如果没混淆 没太过优化 大体能恢复源码 ...
- JavaScript设计模式与开发实践(一)
一.this this的指向大致可以分为以下几种: 作为对象的方法调用 作为普通函数调用 构造器调用 Function.prototype.call或Function.prototype.apply ...
- wget 小技巧
一,案例 wget, 一个强大的下载命令.下载文件如果由于中途因本地网络问题断开了,没下载完,重新运行了一下WGET命令,会发现完全在重新下载了,新文件名字会在后面加个1..... 这是wget下载失 ...
- java 发布订阅
https://www.cnblogs.com/coderdxj/p/9627310.html java 观察这模式(发布订阅模式) 观察者设计模式定义了对象间的一种一对多的组合关系,以便一个对象 ...
- Vue数据通信详解
如果有需要源代码,请猛戳源代码 希望文章给大家些许帮助和启发,麻烦大家在GitHub上面点个赞!!!十分感谢 一.前言 组件是 vue.js最强大的功能之一,而组件实例的作用域是相互独立的,这就意味着 ...
- k8sSecret资源
Secret资源的功能类似于ConfigMap,但它专用于存放敏感数据,如密码.数字证书.私钥.令牌和ssh key等. 一.概述 Secret对象存储数据以键值方式存储数据,再pod资源中通过环境变 ...
- Navicat for Mysql查询结果导出无表名
在查询窗口用select语句按条件查出所需结果,然后用“导出向导”把查询结果导成sql文件,但是导出来的sql语句没有表名了. 导成的sql文件大致是这样的, INSERT INTO `` (`id` ...