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 ...
随机推荐
- vue-路由-显示名称
显示名称 方式1: <div id="app"> <!-- 分析: --> <!-- 1. 我们要监听到 文本框数据的改变,这样才能知道 什么时候去拼 ...
- VUE基础实用技巧
Vue以前听说过,有了解过一点.当时还在热衷于原生JavaScript去写一些方法的封装,不是为啥,就感觉这样很帅,后面多多少少接触了一些JQuery的用法,到现在为止,JavaScript原生封装的 ...
- kali linux查看局域网下所有IP,并对指定IP实施局域网内攻击(断网,随时查看对方密码,上网痕迹等)
首先我们打开我们熟悉的kali linux操作系统,利用指令: ifconfig 来确认本机的ip地址 确认了本机的ip地址之后,利用一下的指令查看局域网下所有ip: fping -g 本机IP地址/ ...
- ubuntu下查看本机IP地址
在终端输入: ifconfig -a 即可得解.出来的结果inet后就是你的ip地址
- curl ftp libcurl 功能使用
struct FtpFile { const char *filename; FILE *stream; }; static size_t my_fwrite(void *buffer, size_t ...
- Android,百度,云知声tts总结
最近在做Android语音播报功能(TTS),现总结如下:(ps:demo代码地址:https://github.com/giserlong/TTS_DEMO) 一.Android原生接口 用Andr ...
- docker部署gitlab-ce
简介 环境准备 centos7 docker 1.13.1 gitlab-ce 安装步骤 1.首先需要从docker镜像仓库当中获取gitlab-ce的最新镜像文件,由于我本机已经获取了该镜像,所以在 ...
- mac odoo 12 虚拟环境搭建及 依赖安装
经过这几天的折腾,odoo 12 的虚拟环境总算搭建成了.网站有很多虚拟环境相关的搭建,但是都是写文章的自己清楚,但是文章里却描述不清楚. odoo 虚拟环境 这次搭建环境使用 odoo 12.0. ...
- SQL常用增删改查语句--来源于网络
1.1[插入单行]insert [into] <表名> (列名) values (列值)例:insert into Strdents (姓名,性别,出生日期) values ('开心朋朋' ...
- [日常] 安装windows+deepin双系统
我的测试电脑上安装了三个系统,分别是win7 , ubuntu16.04 ,deepin15.11下面的步骤是安装deepin系统的过程 1.制作启动u盘,直接使用官方工具制作就可以了,我的已经制作好 ...