判断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. struts2 使用注解方式配置

    1.导入convention 包 2.java: package com.struts.base.hello; import java.io.IOException; import java.io.P ...

  2. windows 下使用 zip安装包安装MySQL 5.7

    以下内容参考官方文档:http://dev.mysql.com/doc/refman/5.7/en/windows-start-command-line.html 解压缩zip到D:\mysql-5. ...

  3. [SQL]获取所有数据库名、获取数据库中表名、获取表中的字段名

    --()获取所有数据库名: Select Name FROM Master..SysDatabases order by Name --()获取所有表名 --XType=''U'':表示所有用户表; ...

  4. [HDU 3033] I love sneakers! (动态规划分组背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3033 题意:给你K种品牌,每种品牌有不同种鞋,现在每种品牌至少挑一款鞋,问获得的最大价值,如果不能每种 ...

  5. history.back(-1)和history.go(-1)的区别

    history.back(-1):直接返回当前页的上一页,数据全部消息,是个新页面 history.go(-1):也是返回当前页的上一页,不过表单里的数据全部还在 返回到指定连接:document.l ...

  6. 双系统下恢复Ubuntu引导菜单

    引言 使用双系统的时候,我们经常重装Windows!那么有没有一种办法:只重装Windows而不重装Ubuntu呢? 在使用Win XP/Ubuntu双系统时,这个问题很好解决!但是在使用Win7(包 ...

  7. android 操作sqlite的一点小技巧

    1.android 在sqlite插入数据时,是非常耗时的操作,原因是sqlite缺省会为每个插入操作开启一个事务,当数量变多的时候,自然时间就变得很慢,这时候可以考虑在插入等操作时先开启一个事务,再 ...

  8. JavaScript instanceof和typeof的区别

    引用自:   http://www.cnblogs.com/eoiioe/archive/2008/12/31/1366081.html instanceof和typeof都能用来判断一个变量是否为空 ...

  9. Git使用手册:HTTPS和SSH方式的区别和使用

    在管理Git项目上,很多时候都是直接使用https url克隆到本地,当然也有有些人使用SSH url克隆到本地.这两种方式的主要区别在于:使用https url克隆对初学者来说会比较方便,复制htt ...

  10. 移动端拖拽(模块化开发,触摸事件,webpack)

    通过jquery可以很容易实现CP端的拖拽.但是在移动端却不好用了.于是我自己写了一个在移动端的拖拽demo,主要用到的事件是触摸事件(touchstart,touchmove和touchend). ...