判断integer是否为回文串(负数全部不为回文串)

思路很直接,提取出integer中的每一位,一头一尾进行比较是否相同。

一次AC , 直接上代码:

public boolean isPalindrome(int x) {
if(x < 0) return false;
else if(x >= 0 && x <= 9) return true;
else{
int[] num = new int[20];
int i = 0 ;
while(x > 0){
num[i++] = x % 10;
x = x / 10;
} int mMax = i / 2,kMin;
if(i % 2 == 1) kMin = i / 2;
else kMin = i / 2 - 1; for(int m = 0 , k = (i-1) ; m < mMax && k > kMin ; m++ , k--){
if(num[m] != num[k]) return false;
}
return true;
}
}

[leetcode]_Palindrome 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. django提供xml下载

    def test_file_download(request): wb = export_to_xls() response = HttpResponse() response['Content-Ty ...

  2. AIX 下某些日志定时清空

    最近发现weblogic proxy日志一直增加,达到18G把tmp空间撑满,导致系统无法访问,故设定时任务先拷贝后5000行日志做备份后清空proxy日志. vi wl_proxyclear.sh ...

  3. A - Red and Black(3.2.1)(小递归)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  4. css 使用background背景实现border边框效果

    css中,我们一般使用border给html元素设置边框,但也可以使用background背景来模拟css边框效果,本文章向大家介绍css 使用background背景实现border边框效果,需要的 ...

  5. 在eclipse中生成html注释文档

    生成api文档 文档注释/** 1.描述 2.@author 作者 @version 版本 3.@param 参数 @return 返回值的含义 @throws 抛出异常描述 @deprecated ...

  6. 《Code Complete》ch.16 控制循环

    WHAT? 反复执行的代码片段(你是第一天学编程吗) WHY? 知道如何使用及何时使用每一种循环是创建高质量软件的一个决定性因素 HOW? 检测位于循环开始/循环结尾 带退出的循环 进入循环 只从一个 ...

  7. 转载:Cocos2D-x 游戏接入 Windows 设备所需做的六件事

    原文地址:http://msopentech.com/zh-hans/blog/2014/05/09/cocos2d-x-%E6%B8%B8%E6%88%8F%E6%8E%A5%E5%85%A5-wi ...

  8. MFC学习 序列化

    void CArchiveView::OnWrite() { // Archive就是可序列化的类, 要头文件中DECLARE_DYNCREATE(CArchiveDoc) // 重写 virtual ...

  9. 【翻译】什么是 eCPM & RPM 与其计算公式

    [原文链接] What is eCPM & RPM. How to Calculate eCPM & RPM using Formula eCPM代表着每千次网页爆光转换率(或者是每千 ...

  10. 002..NET MVC实现自己的TempBag

    原文链接:http://www.dotnetbips.com/articles/bc422c95-02cc-4d05-9c5c-fa89d0e78cc0.aspx 1.前言 本来今天是想发那篇关于在W ...