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 ...
随机推荐
- oracle学习笔记(十八) PL/SQL 游标
游标 说明 查询结果的光标,相当于java中的一个迭代器,方便遍历操作 可使用的属性 %FOUND SQL语句查询或影响了一行或多行时为 TRUE.如:mycursor%FOUND %NOTFOUND ...
- hive 标准hql建表语法格式
一.标准hql建表语法格式1.官方标准语法:(hql不区分大小写,下面[]里的属性是可选属性) 具体参考官网界面:HIVE官网建表说明文档 CREATE [EXTERNAL] TABLE [IF NO ...
- python中反转列表的三种方式
1.内建函数reversed() li =[1, 2, 3, 4, 5, 6] a = list(reversed(li)) print (a) 注意:reversed()函数返回的是一个迭代器,而不 ...
- String字符串是不变对象,内容一旦创建不可改变,若改变一定会创建新对象
package seday01;/** * 字符串是不变对象,内容一旦创建不可改变,若改变一定会创建新对象* @author xingsir */public class StringDemo { p ...
- python数据挖掘之数据探索第一篇
目录 数据质量分析 当我们得到数据后,接下来就是要考虑样本数据集的数据和质量是否满足建模的要求?是否出现不想要的数据?能不能直接看出一些规律或趋势?每个因素之间的关系是什么? 通过检验数据集的 ...
- 在linux上安装postgresql数据库
#postgres useradd postgres chown -R postgres:postgres /media su postgres mkdir -p /media/Data1/postg ...
- 【JavaWeb】Ajax基础
Ajax介绍 Asynchronous JavaScript And XML(异步的JavaScript和XML): Ajax可以在不刷新页面的前提下,进行页面局部更新: Ajax不是新的技术,Aja ...
- 测试文档(final)
1 引言 1.1编写目的 编写本测试计划的目的是: (1) 为整个测试阶段的管理工作和技术工作提供指南同时确定测试的内容和范围,为评价系统提供依据: (2) 此外还帮助安排测试活动,说 ...
- jmeter判断请求响应时间,请求下加‘断言持续时间’,添加监听器断言结果;统计超时
- 自定义安装office
自定义安装office 1.下载office安装包:https://msdn.itellyou.cn 2.下载offiice部署工具:https://www.microsoft.com/en-us/d ...