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 ...
随机推荐
- 【微信小程序】template模板使用详解
WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用. 模板的作用域: 模板拥有自己的作用域,只能使用 data 传入的数据以及模板定义文件中定义的 <wxs / ...
- swif(六)swift闭包
// // main.swift // LessonSwiftSix // // Created by keyan on 15/9/13. // Copyright (c) 2015年 keyan. ...
- 基于file上传文件的并发上传(多个文件一起上传到后台并把数据存储的同一条数据中,如 数据库字段videopath,imge。前台发送来的文件file1,file2。 videopath=file1,imge=file2)
前台代码: <div class="tab-content"> <dl> <dt>所属栏目</dt> <dd> < ...
- 炫彩字and鼠标爱心
<!DOCTYPE html> <style type="text/css"> body{ background-color: black; } #zx { ...
- PyCharm颜色设置
选择主题和背景图片 选择字体.修改字体大小 新建颜色主题 修改背景颜色 修改注释颜色 File --> Setting (Ctrl + Shift + S) 1.选择不同的主题.选择背景图片 A ...
- PyQt5-TableWidget 表格视图
基于PyQt5 postgreSQL实现简单的数据插入.数据表格查询. 运行前需要安装psycopg2 模块,配置好postgerSQL. 先看效果图: 第1列为日期时间.第2列为自增1的编号.第3到 ...
- Java中Class和单例类的作用与类成员的理解
Java中Class类的作用与深入理解 在程序运行期间,Java运行时系统始终为所有的对象维护一个被称为运行时的类型标识.这个信息跟踪着每个对象所属的类.JVM利用运行时信息选择相应的方法执行.而保存 ...
- Tomcat相关目录及配置文件
目录结构 [root@localhost tomcat]# tree -L 1.├── bin├── BUILDING.txt├── conf├── CONTRIBUTING.md├── lib├── ...
- day72_10_17 序列化组件之model的运用
一.拆分的序列化. model序列化的基本用法就是使用元类中的fields,其中model绑定的就是model中的表 如果需要多表查询,要在model中定义property: class BookMo ...
- Redis windows版本资源与安装
这里提供一个windows版本的Redis百度云资源 链接: https://pan.baidu.com/s/19JY_d_J87n98OeAHK9qI4A 密码: d6dq 1,GitHub下载地址 ...