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. SpringMVC 的初理解

    项目中用到了jetty,springboot两种构建服务器的方式,jetty是一种嵌入式的方式,部署启动都很灵活,springboot最大的优点就是很多配置文件都自己集成好了,虽然用了这么多好的框架, ...

  2. [spring] Ioc 基础

    Ioc的理解:调用类对某一接口的实现类的依赖关系又第三方注入,以移除调用类对接口实现类的依赖.又叫做依赖注入.调用者对接口的选择权利被剥夺,交给了第三方.举个例子,学生本来可以选择哪个老师给他上课的, ...

  3. 963 AlvinZH打怪刷经验(背包DP大作战R)

    963 AlvinZH打怪刷经验 思路 这不是一道普通的01背包题.大家仔细观察数据的范围,可以发现如果按常理来的话,背包容量特别大,你也会TLE. 方法一:考虑01背包的一个常数优化----作用甚微 ...

  4. git 克隆 提交本地修改到远程方法

    最近一个项目,提交总报错 按照下面的流程就ok了 $ git clone $ git init $ cd shop $ git branch -al //查看所有分支 $ git pull origi ...

  5. springBoot 实现中文国际化

    一:实现效果如下: 二 SpringBoot 国际化配置 1.创建国际化配置文件(3个): messages.properties messages.user.name=用户名 messages.us ...

  6. 简述Dubbo

    目前处于实习期间,白天工作,网上自主学习.最近没事逛了一下当前招聘网上的招聘要求,其中dubbo这个关键字出现的比较多,因此花了点时间学习了一番,在这写写自己的理解. 说起Dubbo,得先聊聊RPC, ...

  7. 达人篇:2.1)APQP产品质量先期策划

    本章目的:介绍APQP的概念,明确APQP各个阶段提交的内容.理解APQP是帮助而不是负担. APQP概念: 产品质量先期策划(Advanced Product Quality Planning,简称 ...

  8. python 元类以及练习

    ''' # 知识储备exec() # 参数1:字符串形式的命令 # 参数2:全局作用域(字典形式),如果不指定默认就使用globals() # 参数3:局部作用域(字典形式),如果不指定默认就使用lo ...

  9. 剑指offer——面试题22:链表中倒数第k个节点

    注意代码的鲁棒性! 函数: ListNode* TheLastKthNode(ListNode* pHead,int k) { ) return nullptr; ListNode* quickNod ...

  10. mysql for mac 上的安装及用DataGrip连接

    ---恢复内容开始--- 1.首先下载MySQL的mac版本,地址百度就行了. 2.这个时候需要注意安装的时候,弹出来的一个类似窗口,上面有提示默认密码,但是我当时就忘记了这个默认密码,如果你记住了默 ...