题目

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. MySQL 中的索引

    索引用来加速查询.正常来说,当查询数据时,MySQL 需要从表的第一条记录开始,读取整个表的内容,进行查询. 但如果有索引,MySQL 可根据索引快速定位需要查询条目的具体位置,加快了查询速度. 原理 ...

  2. windows环境下安装配置MongoDB

    版本选择MongoDB的版本命名规范如:x.y.z: y为奇数时表示当前版本为开发版,如:2.3.0.2.1.1: y为偶数时表示当前版本为稳定版,如:2.0.1.2.2.0: 目前官网上最新的版本为 ...

  3. Java生鲜电商平台-SpringCloud微服务架构中网络请求性能优化与源码解析

    Java生鲜电商平台-SpringCloud微服务架构中网络请求性能优化与源码解析 说明:Java生鲜电商平台中,由于服务进行了拆分,很多的业务服务导致了请求的网络延迟与性能消耗,对应的这些问题,我们 ...

  4. 五个常用的CSS简写

    1,margin/padding. (演示仅为margin,padding同理,需注意的是padding没有auto) 2.background. background: [background-co ...

  5. centos7下编译安装python3.7,且与python2.7.5共存

    环境:Centos7.6 x64 一.安装python3.7 下载python源码包: wget https://www.python.org/ftp/python/3.7.4/Python-3.7. ...

  6. 关于vue项目中使用组件的一些心得

    在编写一个可能是共组件的情况下,尽量在组件内部只处理相关组件内部的逻辑,组件外的逻辑通过事件总线emit,否则一旦当前组件涉及其他组件的逻辑就会发生耦合,在一个新的组件里面使用的时候,就会造成后悔的情 ...

  7. NSURLSession中的downloadTask的使用

    1.用downloadTask下载图片 优点:简单 缺点:不能监听下载的进度 代码示例: NSURL *url = [NSURL URLWithString:@"http://pic1.wi ...

  8. Mysql 连接提示 Client does not support authentication protocol requested by server 客户端不支持服务器请求的身份验证协议;考虑升级MySQL客户端

    由于查阅了很多百度文档发现很多方法比较复杂,所以写个备忘: 首先,进入MySQL 8.0Command Line Client -Unicode,输入密码,登录进去. 然后,在命令行输入:ALTER ...

  9. Ubuntu 18.04安装 pyenv、pyenv-virtualenv、virtualenv、Numpy、SciPy、Pillow、Matplotlib

    1.目前Python版本管理工具有很多,pyenv是比较好用的一款,安装如下: 输入: git clone https://github.com/pyenv/pyenv.git ~/.pyenv ec ...

  10. 5.Python网络编程_通过继承实现多线程

    import threading import time #继承形式的多线程,适合于程序比较复杂的情况 class MyThread(threading.Thread): #t.start()会调用r ...