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. 2019.2.14 t1 最大公约数

    代码: #include <cstdio> #include <iostream> #include <cstring> #include <algorith ...

  2. P2300 合并神犇

    题目链接 题意分析 首先这道题不可以使用简单的贪心来做 根据\(DP\) 我们令\(dp[i]\)表示当前到了\(i\)一共做了\(dp[i]\)次合并 \(pre[i]\)表示当前合并到了\(i\) ...

  3. 记录两道有趣的有关php数组的面试题

    <?php $arr=[ ['张三','李四','王五'], ['吃鸡','消消乐','火影'], ['25','26','28'], ]; '如何转换为' $arr1=[ ['张三','吃鸡' ...

  4. 2017-2018 ACM-ICPC, Asia Daejeon Regional Contest

    题目传送门 只打了三个小时. A. Broadcast Stations B. Connect3 补题:zz 题解:因为格子是4*4的,而且每次落子的位置最多是只有四个,再加上剪枝,情况不会很多,直接 ...

  5. 爬虫--requeste

    1.requeste模块,是我们Python对我们爬虫有好的一面,,其主要作用是用来模拟浏览器发起请求.功能强大,用法简洁高效.在爬虫领域中占据着半壁江山的地位.没有的话直接pip3 install  ...

  6. Digispark(ATTINY85) 微型开发板驱动安装与开发环境配置教程

    前几天无聊就弄了弄这个玩,网上教程可能有点杂,在这里就总结一下. Digispark开发板(也就是badusb)能干什么,自己搜去,/坏笑. 1.准备材料:Attiny85微型 USB接口开发板 Di ...

  7. Jmeter性能测试之添加思考时间

    利用定时器添加用户思考时间 JMeter如何插入思考时间,在一个真实的性能测试场景中,是需要加入思考时间,来模拟真实用户行为.本文就来介绍,如何在三个请求之间添加思考时间. 1. 在Test Plan ...

  8. 等待页面元素(webdriverwait)

    前言 在脚本中加入太多的 sleep 后会影响脚本的执行速度,虽然 implicitly_wait ()这种方法隐式等待方法一定程度上节省了很多时间.但是一旦页面上某些 js 无法加载出来(其实界面元 ...

  9. 【CSS】 布局之圣杯布局

    在看众多大神的css布局指南时,经常看到一个布局:圣杯布局(也有称为双飞翼布局的).今天我们也来剖析一下. 其实,对于众多css布局,我们只要明确理解了3种技术,那么基本上大多数布局都难不倒我们了: ...

  10. 深入理解BSS(Block Started by Symbol)

    理解ELF的BSS section, 可以概括为: Uninitialized global/static data "Block Started by Symbol" " ...