LeetCode题解之Rotated Digits
1、题目描述
2、代码
int rotatedDigits(int N) {
int res = ; for (int i = ; i <= N; i++) {
if (isGood(i)) {
res++;
}
} return res;
} bool isGood(int x)
{
int rx = x;
vector<int> nums;
while (x) {
int r = x % ;
nums.push_back(r);
x = x / ;
} for (vector<int>::iterator it = nums.begin(); it != nums.end(); it++ ) {
if (*it == || *it == || *it == )
return false;
if (*it == || *it == || *it == )
continue; if (*it == ) {
*it = ;
continue;
} if (*it == ) {
*it = ;
continue;
} if (*it == ) {
*it = ;
continue;
} if (*it == ) {
*it = ;
continue;
}
} int good = ;
for (vector<int>::reverse_iterator ite = nums.rbegin(); ite != nums.rend(); ite++) {
good = good * + *ite;
} return good != rx;
}
LeetCode题解之Rotated Digits的更多相关文章
- LeetCode算法题-Rotated Digits(Java实现)
这是悦乐书的第316次更新,第337篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第185题(顺位题号是788).如果一个数字经过180度旋转后,变成了一个与原数字不同的 ...
- 【LeetCode】788. Rotated Digits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode 题解之Add Digits
1.问题描述 2.问题分析 循环拆分数字,然求和判断. 3.代码 int addDigits(int num) { ) return num; int result = num; do{ vector ...
- 73th LeetCode Weekly Contest Rotated Digits
X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...
- [LeetCode 题解] Search in Rotated Sorted Array
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 题目描述 Suppose an array ...
- LeetCode 788. 旋转数字(Rotated Digits) 36
788. 旋转数字 788. Rotated Digits 题目描述 我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数.要求每位数字 ...
- [LeetCode 题解]:Palindrome Number
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Determine ...
- [LeetCode 题解]:Intersection of Two Linked Lists
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Suppose an ...
- [LeetCode 题解]: plusOne
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a no ...
随机推荐
- Your Mac is infected with (3) Viruses!
记一次流氓程序的清理 某天我的电脑不幸感染了这么一个病毒
- IDEA中Git的使用基础
场景概述 工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 ...
- Java NIO 基础知识
前言 前言部分是科普,读者可自行选择是否阅读这部分内容. 为什么我们需要关心 NIO?我想很多业务猿都会有这个疑问. 我在工作的前两年对这个问题也很不解,因为那个时候我认为自己已经非常熟悉 IO 操作 ...
- php获取 POST请求的数据
普通键值对的数据: $_POST[‘username’]; // 获取 username的信息: $_REQUEST; //则会获取 整个请求中的键值对,返回结果为数组: 如果是,流数据,则需要使用: ...
- 【IT笔试面试题整理】二叉搜索树转换为双向链表
[试题描述] 将二叉搜索树转换为双向链表 对于二叉搜索树,可以将其转换为双向链表,其中,节点的左子树指针在链表中指向前一个节点,右子树指针在链表中指向后一个节点. 思路一: 采用递归思想,对于二叉搜索 ...
- Centos7下使用yum安装lnmp zabbix3.2
1:配置epel-release mysql zabbix 源 配置epel源 wget http://mirrors.aliyun.com/epel/epel-release-latest-7.no ...
- SQL-结构化查询语言(2)
使用explain查询select查询语句的执行计划 mysql> explain select * from student where Sname='金克斯'\G ************* ...
- java为什么使用TypeReference
用途 在使用fastJson时,对于泛型的反序列化很多场景下都会使用到TypeReference,例如: void testTypeReference() { List<Integer> ...
- SQL语句大全从基础到熟练(不含数据库高端操作)日常用户 三、
前言 昨天晚上回家忘记带钥匙导致在楼下站街三小时,鬼天气热的不要不要的然后我就在车里坐了会之后就.....zzZZ,哈哈睡的挺香的毕竟累了一天了 上两篇文章都是介绍的语法语句,本篇文章介绍下函数的使用 ...
- Linux常用基本命令(split )
split命令 作用:切割文件 格式: split [option] [input] [prefix] -l 指定分割后文件的最大行数 ghostwu@dev:~/linux/split$ cat - ...