LeetCode 1291. Sequential Digits
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的更多相关文章
- 【leetcode】1291. Sequential Digits
题目如下: An integer has sequential digits if and only if each digit in the number is one more than the ...
- [LeetCode] Reconstruct Original Digits from English 从英文中重建数字
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the ...
- [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] Monotone Increasing Digits 单调递增数字
Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...
- LeetCode:Add Digits - 非负整数各位相加
1.题目名称 Add Digits (非负整数各位相加) 2.题目地址 https://leetcode.com/problems/add-digits/ 3.题目内容 英文:Given a non- ...
- LeetCode 258 Add Digits(数字相加,数字根)
翻译 给定一个非负整型数字,反复相加其全部的数字直到最后的结果仅仅有一位数. 比如: 给定sum = 38,这个过程就像是:3 + 8 = 11.1 + 1 = 2.由于2仅仅有一位数.所以返回它. ...
- [LeetCode] 258. Add Digits 加数字
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- LeetCode 258. Add Digits
Problem: Given a non-negative integer num, repeatedly add all its digits until the result has only o ...
- 【LeetCode】Add Digits
Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...
随机推荐
- GO的执行原理以及GO命令
Go的执行原理以及Go的命令 一.Go的源码文件 Go 的源码文件分类: 如上图,分为三类: 1.命令源码文件: 声明自己属于 main 代码包.包含无参数声明和结果声明的 main 函数. 命令源码 ...
- VS Code 快捷键 && 常用插件
常用插件 分类 插件名称 说明 开发 C# C#语言 C# Extensions C#扩展功能(添加类,接口,智能提示) C# XML Documentation Comments 代码添加注释 ...
- K60时钟分析
转载:https://blog.csdn.net/hcx25909/article/details/7164650 1.飞思卡尔K60时钟系统 飞思卡尔K60时钟系统如上图所示,可以 ...
- ENVOIA
1,ENVOIA 组织架构讲解 2,开发中的各文件详细讲解 3,系统Data Model讲解 ENOVIA 2012 Online doc文档简介. 介绍ENOVIA组织架构. 介绍ENOVIA前身M ...
- zip unzip 压缩解压缩命令
直接上例子: mkdir test1 touch test1/1.txt touch test1/2.txt zip -r test1.zip test1 #-r 参数是包含文件夹下的文件 un ...
- I2C硬件与模拟的区别
硬件I2C对应芯片上的I2C外设,有相应I2C驱动电路,其所使用的I2C管脚也是专用的,因而效率要远高于软件模拟的I2C:一般也较为稳定,但是程序较为繁琐. 硬件(固件)I2C是直接调用内部寄存器进行 ...
- 2. Vue - 初始
一.vue简单介绍 1. vue定义 vue是一套用于构建用户界面的渐进式框架.vue被设计为可自底向上逐层应用,vue的核心只关注视图层:vue的特点是数据驱动视图,可直接修改数据,不用再手动编 ...
- pushgateway
下载pushgateway wget https://github.com/prometheus/pushgateway/releases/download/v0.9.0/pushgateway-0. ...
- Pwn-pwn-200
题目地址 ttp://www.whalectf.xin/files/47a658e388a0c505fc07b6ee48a4a2e2/binary_200 32位,开启了NX和Canary保护 存在字 ...
- oracle 周岁年龄计算
以下三种方法均可实现周岁年龄的计算: --算法一: SELECT TRUNC(months_between(sysdate, csrq)/12) AS "Age" FROM wrx ...