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 ...
随机推荐
- fastjson的值过滤器ValueFilter
https://blog.csdn.net/linyifan_/article/details/83060408 原创林天乐 发布于2018-10-15 16:20:25 阅读数 1462 收藏 展 ...
- 2018-12-25-win10-uwp-通知列表
原文:2018-12-25-win10-uwp-通知列表 title author date CreateTime categories win10 uwp 通知列表 lindexi 2018-12- ...
- 使用c#创建Excel 2013外接程序
心好累,印象笔记国内版和国际版账号还不能通用,在国内版写了一个没法创建共享链接(只有共享给XXemail),于是又写了一遍到国际版上(因为图片无法复制,又copy了一遍图片),现在copy到博客园,图 ...
- Python 容器使用的 5 个技巧和 2 个误区
"容器"这两个字很少被 Python 技术文章提起.一看到"容器",大家想到的多是那头蓝色小鲸鱼:Docker,但这篇文章和它没有任何关系.本文里的容器,是 P ...
- django6-orm进阶操作
1.创建django环境的脚本 在自定义脚本中操作orm ,但是自定义脚本中不具备django的环境 ###test.py 脚本,引入django的环境即可使用orm操作数据库import os if ...
- Android框架Volley之:利用Imageloader和NetWorkImageView加载图片
首先我们在项目中导入这个框架: implementation 'com.mcxiaoke.volley:library:1.0.19' 在AndroidManifest文件当中添加网络权限: < ...
- 数据库 OR 运维 ____bayaim
最近一直在思考,想想未来的道路和自己努力的方向.马云曾说过现在的年轻人缺少“慢下来”,只有人慢下来才能更好思考,想好方法和目标才更靠近才成功.如果,一直不停的努力,在错误的道路越走越远,势必会浪费时间 ...
- STL顺序容器的基本操作
容器主要分为:顺序容器和关联容器 顺序容器和关联容器,顺序容器主要有:vector.list.deque等.其中vector表示一段连续的内存地址,基于数组的实现,list表示非连续的内存,基于链表实 ...
- python语法区别
python语法区别: 大小写敏感 (动态语言:python)变量不用声明 p.s: 静态语言(Java)必须声明变量 语句末尾可以不打分号 可以直接进行数学计算 复制.粘贴功能失效,粘贴到别的地方的 ...
- 【bzoj3601】一个人的数论(莫比乌斯反演+拉格朗日插值)
传送门 题意: 求\[ \sum_{i=1}^{n}i^d[gcd(i,n)=1] \] 思路: 我们对上面的式子进行变换,有: \[ \begin{aligned} &\sum_{i=1}^ ...