leetcode660. Remove 9
leetcode660. Remove 9
题意:
从整数1开始,删除任何包含9的整数,如9,19,29 ...
所以现在,你将有一个新的整数序列:1,2,3,4,5,6,7,8,10,11,...
给定正整数n,您需要在删除后返回第n个整数。注意1将是第一个整数。
思路:
因为要去除所有的包含9的数。转化成9进制就好了???真是奇巧淫技呀。
ac代码:
C++
class Solution {
public:
int newInteger(int n) {
int res = 0, count = 1;
while(n)
{
res = res + (n % 9) * count;
n /= 9;
count *= 10;
}
return res;
}
};
python
class Solution:
def newInteger(self, n):
"""
:type n: int
:rtype: int
"""
res = 0
count = 1
while n:
res += (n % 9) * count
count *= 10
n //= 9
return res
leetcode660. Remove 9的更多相关文章
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...
- [LeetCode] Remove K Digits 去掉K位数字
Given a non-negative integer num represented as a string, remove k digits from the number so that th ...
- [LeetCode] Remove Duplicate Letters 移除重复字母
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- [LeetCode] Remove Invalid Parentheses 移除非法括号
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...
- [LeetCode] Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- [LeetCode] Remove Duplicates from Sorted List 移除有序链表中的重复项
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Remove Element 移除元素
Given an array and a value, remove all instances of that value in place and return the new length. T ...
随机推荐
- 含有ref out 参数 的方法反射 Emit 与 普通
反射中很多朋友应该屡屡被带有ref out参数的方法折腾 当使用正常反射一个方法时候: 代码如下调用一个后期绑定方法MakeByRefType 就行了 MemberInfo test = typeof ...
- go语言 documentation
Documentation文档 The Go programming language is an open source project to make programmers more pro ...
- 基于vue配置axios
转载地址:https://juejin.im/post/5a02a898f265da43052e0c85 1.背景 在项目开发中ajax请求是必不可缺少 一部分ajax请求不需要loading或则请求 ...
- Elasticsearch 邻近查询示例
Elasticsearch 邻近查询示例(全切分分词) JAVA API方式: SpanNearQueryBuilder span = QueryBuilders.spanNearQuery(); s ...
- 洛谷P3385负环
传送门 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...
- LeetCode699. Falling Squares
On an infinite number line (x-axis), we drop given squares in the order they are given. The i-th squ ...
- redux-saga印象
saga作为redux的中间件,用来处理异步任务. 先收集资料: 贴个文章(2)中的图先: 注意:参考文献(4)是redux-saga作者写的. 参考文章: (1)https://redux-saga ...
- PHP XML操作的各种方法解析
PHP提供了一整套的读取 XML文件的方法,很容易的就可以编写基于 XML的脚本程序.本章将要介绍 PHP与 XML的操作方法,并对几个常用的 XML类库做一些简要介绍. XML是一种流行的半结构化文 ...
- 一步一步学习IdentityServer3 (7)
在介绍自定义用户服务之前先对IdentityServerServiceFactory说明下 Idr3的服务工厂 下面有很多idr3提供的接口服务, 如:ViewService.UserService. ...
- CCF CSP 201509-4 高速公路
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201509-4 高速公路 问题描述 某国有n个城市,为了使得城市间的交通更便利,该国国王打算在 ...