题目

class Solution {
public:
int ans[10005];
vector<int> sequentialDigits(int low, int high) { int x = 1;
int pos=0;
int tag=1;
for(int i=1;i<=9;i++)
{
x=fun2(x);
tag*=10;
int xx=x;
for(int j=1;j<=9-i;j++)
{
ans[pos++]=xx; xx=fun(xx,tag);
} } vector<int> res;
int tag2=0;
for(int i=0;i<pos;i++)
{
if(ans[i]>=low&&ans[i]<=high)
{
res.push_back(ans[i]);
} }
return res; } int fun(int x,int num)
{
int y =x%10; x%=num; x*=10;
x+=y+1;
return x;
} int fun2(int x)
{
int y = x%10;
x*=10;
x+=y+1; return x;
}
};

LeetCode 1291. Sequential Digits的更多相关文章

  1. 【leetcode】1291. Sequential Digits

    题目如下: An integer has sequential digits if and only if each digit in the number is one more than the ...

  2. [LeetCode] Reconstruct Original Digits from English 从英文中重建数字

    Given a non-empty string containing an out-of-order English representation of digits 0-9, output the ...

  3. [LeetCode] Remove K Digits 去掉K位数字

    Given a non-negative integer num represented as a string, remove k digits from the number so that th ...

  4. [LeetCode] Monotone Increasing Digits 单调递增数字

    Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...

  5. LeetCode:Add Digits - 非负整数各位相加

    1.题目名称 Add Digits (非负整数各位相加) 2.题目地址 https://leetcode.com/problems/add-digits/ 3.题目内容 英文:Given a non- ...

  6. LeetCode 258 Add Digits(数字相加,数字根)

    翻译 给定一个非负整型数字,反复相加其全部的数字直到最后的结果仅仅有一位数. 比如: 给定sum = 38,这个过程就像是:3 + 8 = 11.1 + 1 = 2.由于2仅仅有一位数.所以返回它. ...

  7. [LeetCode] 258. Add Digits 加数字

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  8. LeetCode 258. Add Digits

    Problem: Given a non-negative integer num, repeatedly add all its digits until the result has only o ...

  9. 【LeetCode】Add Digits

    Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...

随机推荐

  1. 接口的 COM 组件调用 QueryInterface 因以下错误而失败: 库没有注册。

    这个问题原因是因为安装了高版本的office然后卸载掉,又安装了低版本的office导致的. 博主是 office2016卸载后,安装了office2013. EXCEL报错信息为: 无法将类型为“M ...

  2. hello tensorflow,我的第一个tensorflow程序

    上代码: import tensorflow as tf if __name__=='__main__': g = tf.Graph() # add ops to the user created g ...

  3. Java性能 -- Lock优化

    Lock / synchronized Lock锁的基本操作是通过乐观锁实现的,由于Lock锁也会在阻塞时被挂起,依然属于悲观锁   synchronized Lock 实现方式 JVM层实现 Jav ...

  4. 【转载】每个 Android 开发者必须知道的消息机制问题总结

    Android的消息机制几乎是面试必问的话题,当然也并不是因为面试,而去学习,更重要的是它在Android的开发中是必不可少的,占着举足轻重的地位,所以弄懂它是很有必要的.下面就来说说最基本的东西. ...

  5. 实战FFmpeg--编译iOS平台使用的FFmpeg库(支持arm64的FFmpeg2.6.2)

    编译环境:Mac OS X 10.10.2 ,Xcode 6.3  iOS SDK 8.3        FFmpeg库的下载地址是 http://www.ffmpeg.org/releases/ . ...

  6. [b0002] Hadoop HDFS cmd常用命令练手

    目的: 学会HDFS CLI 常用操作 环境: Hadoop 2.6.4 伪分布式版 环境搭建参考本博客前篇文章: 伪分布式 hadoop 2.6.4 帮助: hadoop@ssmaster:~$ h ...

  7. docker 安装 rabbitMQ服务器

    1. 镜像拉取 拉取rabbitMQ镜像文件,后边要接上 management 表名是拉取带有web管理端的镜像,有web界面方便管理. 2.默认用户运行镜像 docker run -d -p 567 ...

  8. 1. Git初始

    一.Git初始 1. 定义 ​ 分布式的版本控制系统,在每个使用者电脑上就有一个完整的数据仓库,没有网络依然可以使用Git.当然为了习惯及团队协作,会将本地数据同步到Git服务器或者GitHub等代码 ...

  9. 爬虫scrapy模块

    首先下载scrapy模块 这里有惊喜 https://www.cnblogs.com/bobo-zhang/p/10068997.html 创建一个scrapy文件 首先在终端找到一个文件夹 输入 s ...

  10. you have new mail in /var/spool/mail/root !

    今天开发的同事告诉我,他在登录系统时老是提示you have new mail in /var/spool/mail/root ! 我一猜就知道他们肯定又自己写定时任务了,这样的事已经发生过好几回了, ...