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 ...
随机推荐
- .net core2 mvc项目中,加入RazorPages页面
2017.08.22 试验结果: 1.手工添加/Pages文件夹 2.复制/Views/_ViewImports.cshtml到/Pages/_ViewImports.cshtml 2.1 修改@u ...
- JavaScript -- Anchor
-----052-Anchor.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=" ...
- linux下mysql5.7以上my.cnf配置文件配置
简单配置,低配置服务器配置 [client] #客户端设置 port = 3306 socket = /data/mysql/data/mysql.sock default-character-set ...
- 【详解】JNI (Java Native Interface) (四)
案例四:回调实例方法与静态方法 描述:此案例将通过Java调用的C语言代码回调Java方法. 要想调用实例对象的方法,需要进行以下步骤: 1. 通过对象实例,获取到对象类的引用 => GetO ...
- 【IT笔试面试题整理】判断一个树是否是另一个的子树
[试题描述]定义一个函数,输入判断一个树是否是另一个对的子树 You have two very large binary trees: T1, with millions of nodes, and ...
- springMVC实现 MultipartFile 多文件上传
1.Maven引入所需的 jar 包(或自行下载) <dependency> <groupId>commons-io</groupId> <artifactI ...
- HDU 1576 A/B(欧几里德算法延伸)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1576 题目: Problem Description 要求(A/B)%9973,但由于A很大,我们只 ...
- Huffman树与编码
带权路径最小的二叉树称为最优二叉树或Huffman(哈夫曼树). Huffman树的构造 将节点的权值存入数组中,由数组开始构造Huffman树.初始化指针数组,指针指向含有权值的孤立节点. b = ...
- 并发编程 —— Timer 源码分析
前言 在平时的开发中,肯定需要使用定时任务,而 Java 1.3 版本提供了一个 java.util.Timer 定时任务类.今天一起来看看这个类. 1.API 介绍 Timer 相关的有 3 个类: ...
- the first blog in 2017——《论作为程序员的我考研》
怎么说,人总是有了压力才有动力.想来如今已经是2017年2月13日,2017年已经使用了43天,距离成绩出来还有3天.这个过年是最不充实的一个年,也是时间长达一个月久的“寒假”,因为“考研”.至于考到 ...