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 ...
随机推荐
- git —— pycharm+git管理/编辑项目
pycharm+git 管理/编辑项目 一.pycharm中配置github 二.配置git 并不是配置了GitHub就可以的.还需要配置一下Git 前提是本地中已经安装了git 三.把本地项目上传 ...
- Tomcat 上传war包后 会自动部署
- 20155225 2016-2017-2《Java程序设计》课程总结
20155225 2016-2017-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1:新的开始 预备作业2:C语言学习回顾 预备作业3:Linux基础入门和虚拟机的安装 第一 ...
- 20165333 2016-2017-2 《Java程序设计》第1周学习总结
20165333 2016-2017-2 <Java程序设计>第1周学习总结 教材学习内容总结 java 的地位 Java 的特点 安装JDK 系统环境的设置 Java程序的编写,编译和运 ...
- mysql 通过sqoop导入hive
sudo -u hdfs sqoop import --connect jdbc:mysql://192.168.33.93:3306/leochentest --username root --pa ...
- Java与Redis
1.下载Java使用Redis架包并引入 jedis-2.9.0.jar 2.用Java使用Redis如下: package com.jef.redis; import redis.clients.j ...
- TCP、UDP、HTTP、SOCKET之间的区别与联系
IP:网络层协议: TCP和UDP:传输层协议: HTTP:应用层协议: SOCKET:TCP/IP网络的API. TCP/IP代表传输控制协议/网际协议,指的是一系列协议. TCP和UDP使用IP协 ...
- ref:JAVA之Forward和Redirect的区别
ref:https://www.cnblogs.com/selene/p/4518246.html 阅读目录 一:间接请求转发(Redirect) 二:直接请求转发(Forward) 用户向服务器发送 ...
- Python并发编程-IO模型-非阻塞IO实现SocketServer
Server.py import socket sk = socket.socket() sk.bind(('127.0.0.1',8080)) sk.setblocking(False) #把soc ...
- 洛谷——P2936 [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...