LeetCode Palidrome Number
class Solution {
public:
bool isPalindrome(int x) {
if (x < ) return false;
int pow = ;
int t = x;
int cnt = ;
while(t /= ) {
pow *= ;
cnt++;
}
t = x;
cnt = cnt / ;
while (cnt--) {
if ((t / pow % ) != t % ) return false;
t = t / ;
pow /= ;
}
return true;
}
};
500ms+,怎么会那么长时间
第二轮:
Determine whether an integer is a palindrome. Do this without extra space.
还是出了点差错,负数不算回文
// 19:50
class Solution {
public:
bool isPalindrome(int x) {
if (x < ) return false;
int n = x;
int cnt = ; do {
cnt++;
x = x/;
} while (x); int tens = ;
for (int i=; i<cnt; i++) {
tens = tens*;
} for (int i=cnt/-; i>=; i--) {
int a = n / tens;
int b = n % ;
n = n - a * tens;
n = n / ;
if (a != b) {
return false;
}
tens = tens/;
}
return true;
}
};
LeetCode Palidrome Number的更多相关文章
- C#版 - Leetcode 191. Number of 1 Bits-题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- [leetcode]200. Number of Islands岛屿个数
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- [leetcode]694. Number of Distinct Islands你究竟有几个异小岛?
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- [LeetCode] 711. Number of Distinct Islands II_hard tag: DFS
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- [LeetCode] 694. Number of Distinct Islands
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- 力不从心 Leetcode(ugly number heap) 263, 264,313
Leetcode ugly number set (3 now) new ugly number is generated by multiplying a prime with previous g ...
- [LeetCode] 200. Number of Islands 岛屿的数量
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- [LeetCode] 305. Number of Islands II 岛屿的数量 II
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...
- [LeetCode] 323. Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
随机推荐
- ubuntu15.04下安装jdk8
前几天手贱,删掉了ubuntu自带的java,最后安装时遇到了Picked up JAVA_TOOL_OPTIONS的问题,经过网上各种找,终于被我弄成功了.下面将经验下载下面供大家方便: jdk8的 ...
- Python的编码详解
一. 编码介绍 计算机只能处理数字(最底层的0和1),如果要处理文本,就必须将文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节(byte),所以一个字节能表示的最大整数就 ...
- python高级(六)——用一等函数实现设计模式
本文主要内容 经典的“策略”模式 python高级——目录 文中代码均放在github上:https://github.com/ampeeg/cnblogs/tree/master/python高级 ...
- Windows下代替自带cmd的开源软件cmder
cmder cmder是一个增强型命令行工具,不仅可以使用windows下的所有命令,更爽的是可以使用linux的命令,shell命令 下载 Cmder官网 下载的时候,会有两个版本,分别是mini与 ...
- linux操作python
Linux安装python3: sudo apt-get install python3.5 安装python库 sudo apt-get install python3-setuptools sud ...
- 安装Telerik JustMock插件后启动不成功
1.打开Telerik JustMock Configuration 勾选所有框 2.到C:\Program Files (x86)\Progress\Telerik JustMock\Librari ...
- 详解exif.js,应用于canvas照片倒转(海报H5)
业务背景,苹果手机调用上传接口拍照没有问题但是上传到网页上照片倒转了解决方法利用exif.js读取图片参数并对图片进行元数据修改 window.btoa(str)转码 window.atob(base ...
- Linux下日志文件监控系统Logwatch的使用记录
Linux下日志文件监控系统Logwatch的使用记录 原文:http://www.cnblogs.com/kevingrace/p/6519504.html 在维护Linux服务器时,经常需要查看系 ...
- 读写锁--ReentrantReadWriteLock
读写锁,对于读操作来说是共享锁,对于写操作来说是排他锁,两种操作都可重入的一种锁.底层也是用AQS来实现的,我们来看一下它的结构跟代码: ------------------------------- ...
- HTTP 状态代码之汇总+理解
这里有百度百科的介绍,还挺全的. 下面是在开发过程中遇到过的各种码,自己的问题自己的原因,同码不同错,贱笑贱笑. HTTP 406 Not Acceptable 这个错误的原因,是由于框架使用了`Sp ...