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的更多相关文章

  1. C#版 - Leetcode 191. Number of 1 Bits-题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  2. [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 ...

  3. [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 ...

  4. [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 ...

  5. [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 ...

  6. 力不从心 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 ...

  7. [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 ...

  8. [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 ...

  9. [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), ...

随机推荐

  1. Windows Server 2008 R2 下 Core界面

    Windows Server 2008 R2 下 Core界面 关于 sc 以及 net 命令 Sc 命令较不全面,仅仅是给服务发送一个开启或者关闭就结束了 Net 命令比较安全,它监视了整个服务的启 ...

  2. jquery中的正则表达式

    1.什么是正则表达式: 能让计算机读懂的字符串匹配规则. 2.正则表达式的写法: var re=new RegExp('规则', '可选参数');var re=/规则/修饰参数; 3.规则中的字符 1 ...

  3. c语言-求完全数的一个算法

    #include<iostream> #include<math.h> using namespace std; int main() { int n,i,j=0,k,a[10 ...

  4. 搭建gogs

    https://blog.csdn.net/hwm_life/article/details/82969005 服务器环境 CentOS 7 64位 安装Gogs所需的其它环境 需要安装的依赖有Ngi ...

  5. leetcode 191:统计1的个数;5 最长回文串;54,59 蛇形矩阵

    class Solution { public: int hammingWeight(uint32_t n) { ; //统计次数 ){ n &= (n-); //每次消掉一个1 k++; / ...

  6. django 迁移工程数据库无法创建的问题

    1.今天我遇到一个问题在此做笔记记下来 2.我晚上一般是在家练习的,白天会拷贝工程到公司用 3.因为我在家里创建过一次数据库了,通过命令创建,但是无论我怎么修改models都无法创建表,最后只能通过新 ...

  7. Android微信支付流程及返回码-1之坑

    http://www.51testing.com/html/36/n-3724336.html 之前做微信支付的时候,直接是以库形式引入项目的,虽然一直觉得微信支付的开发文档不太理想,但是印象中也没有 ...

  8. 2017 FVDI2 ABRITES Commander with 18 Softwares FULL Version + FLY OBD Terminator + J2534 DrewTech Softwares

    Highlights of FVDI2 Abrites Commander Full Version: 1.Free update online. 2.This is full version FVD ...

  9. JobScheduler布置后台任务以及实现进程保活?

    1.简介 在Android 5.0 提供了一套新的 JobScheduler API,它允许您定义要在以后的某个时间或在指定的条件下(例如,当设备在充电时)异步运行的作业来优化电池寿命. https: ...

  10. Docker - 故障排查指南

    这阵子开始捣鼓 Docker,遇到过不少问题,下面记录下问题以及解决方案 一.Docker 报 Failed to start Docker Application Container Engine ...