[leetcode]_Palindrome Number
判断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的更多相关文章
- C#版 - Leetcode 191. Number of 1 Bits-题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- 力不从心 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 ...
- [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 ...
- [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 ...
- [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), ...
随机推荐
- Go Mobile 例子 basic 源码分析
OpenGL ES(OpenGL for Embedded Systems)是 OpenGL 三维图形API的子集,针对手机.PDA和游戏主机等嵌入式设备而设计.该API由Khronos集团定义推广, ...
- Adobe AIR socket complicating 导致 socket RST
基于socket实现HTTP协议 并发请求AB,A为HTTP请求,B为socket请求. A的请求服务器返回数据很短,包体长度只有35,且客户端收到包头后就断开连接,同时A连接的服务器也断开了连接, ...
- sqoop安装
环境:Hadoop 2.3.0 sqoop 1.4.5 1.下载并解压sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz (解压完,名字会很长,可以根据需要自己修改下 ...
- 基于RDBMS的BI设计
================================ 都说BI,什么OLAP,什么ROLAP,MOLAP,但是如何基于RDBMS实现,基本都不怎么说. 怎么做的: 1.通过多维分析模型,存 ...
- PetaPoco修改
else if (type == typeof(decimal)) return (decimal)pk == default(decimal); public override void PreEx ...
- OC基础(5)
#pragma mark指令 description方法 OC多文件开发介绍 *:first-child { margin-top: 0 !important; } body > *:last- ...
- SparkSQL使用之JDBC代码访问Thrift JDBC Server
启动ThriftJDBCServer: cd $SPARK_HOME/sbin start-thriftserver.sh & 使用jdbc访问ThriftJDBCServer代码段: pac ...
- VS集成Qt环境搭建
环境:VS2010 + Qt5.2 关于VS的下载.安装,这里就不再做过多阐述. 一.下载Qt5.2安装包(qt-windows-opensource)与Qt插件(Visual Studio Add- ...
- 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序的处理方式
今天客户向我反映一个问题,当他们在用我们的系统导出excel表格时,报错:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序 经过找资料终于得到解决方法,记录一下. 在对应 ...
- 用Ultra ISO制作启动U盘装系统
用UltraISO制作启动U盘可以在没有光驱的情况下装系统. 现在有大容量U盘的越来越多,而且不装光驱的也越来越多. 那么用U盘装系统成为了可能和必须,不多废话了. 首先,需要准备的有: Ultra ...