判断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. Oracle中的自增-序列-SEQUENCE

    Oracle 12c 之前的版本都没有自增列,如果需要使用自增列,则需要借助SEQUENCE. DROP TABLE CUSTOMERORDER PURGE; CREATE TABLE CUSTOME ...

  2. SPCOMM 接收数据不完整!该如何解决

    SPCOMM 接收数据不完整!该如何解决   SPCOMM 接收数据不完整!我作了一个 读取地磅数据的程序,是用spcomm接收的! 总共有五台地磅,其他4台地磅数据读取都正常.但是有一台接收数据的时 ...

  3. CodeForces 604D 【离散数学 置换群】

    题意: 给你一个方程,方程太变态不打,给你一个p一个k,p保证是大于等于3的质数,k保证在0~p-1之间的整数.要求对应函数的定义域在0~p-1值域为0~p-1的子集,求这样的函数有多少个... 分析 ...

  4. SQL Developer不能删除和复制及部分键失效问题

    打开SQL Developer工作表进行SQL代码的编写的时候,发现我不能使用回车换行键,然后陆续发现好多按键在SQL Developer中都不能正常使用,如:上下左右键只有上和右可以使用,不能使用D ...

  5. archlinux log 文件查看

    # pacman -S gnome-system-log gnome-logsextra/gnome-logs 3.12.1-1 (gnome-extra) A log viewer for the ...

  6. opencv编程解决warning C4003: “max”宏的实参不足

    忘了把程序出错的代码附上了,运行修改好的程序才发现的.只好把问题的代码大致写一下了: warning C4003: “min”宏的实参不足 error C2589: “(”:“::”右边的非法标记 e ...

  7. 利用Meida Service的Java SDK来调用Azure Media Services的Index V2实现视频字幕自动识别

    Azure Media Services新的Index V2 支持自动将视频文件中的语音自动识别成字幕文件WebVtt,非常方便的就可以跟Azure Media Player集成,将一个原来没字幕的视 ...

  8. MVC+EF更新数据库

    要使用代码先行提供的迁移功能来保证模型和数据库自动匹配,在库程序包管理器里依次执行以下命令:1.启用迁移功能:Enable-Migrations -ContextTypeName MvcMovie.M ...

  9. 缓存之Memcached

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

  10. win7下eclipse中文字显示过小

    用win7英文版系统,在eclipse里输入中文字的时候小的可怜,今天实在忍不下去了,随网上搜了搜找到了解决办法,记录下来备用. 操作步骤:打开Elcipse --点击菜单栏上的 “Windows”— ...