[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), ...
随机推荐
- 当月 当年sql
本文转自:http://jophy.javaeye.com/blog/337321 当月数据 Java代码 select * from table t where t.create_time > ...
- [ActionScript 3.0] AS3 判断字符串是否为数字
trace(isNaN(Number("0")));//false trace(isNaN(Number("123")));//false trace(isNa ...
- 有没有一行文件字过多后可以省略号显示,我说的不是用其他样式,BT本身有没有?谢谢
.text-overflow {display: inline-block;max-width: 200px;overflow: hidden;text-overflow: ellipsis;whit ...
- 第七届蓝桥杯C++B组省赛
1.煤球数目 2.生日蜡烛 3.凑算式 4.快速排序 5.抽签 6.方格填数 7.剪邮票 8.四平方和 9.交换瓶子 10.最大比例 今天是周三了,周天刚考完,这次做的还是不好(上次是全省最后一名). ...
- (medium)LeetCode 224.Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- ASP.Net软件工程师基础(四)
1.接口 (1)接口是一种规范.协议,定义了一组具有各种功能的方法(属性.索引器本质是方法). (2)接口存在的意义:多态.多态的意义:程序可扩展性. (3)接口解决了类的多继承的问题. (4)接口解 ...
- Objective-C 2.0的运行时编程
Objective-C 2.0 的运行时环境叫做Morden Runtime,iOS 和Mac OS X 64-bit 的程序都运行在这个环境,也就是说Mac OS X 32-bit 的程序运行在旧的 ...
- pm剩余要看的内容
1. thermal profiles tuning, customize thermal daemon for different thermal usage model 2.gas gauge d ...
- HDU 4738 Caocao's Bridges
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- SVN+FTP服务器搭建(一)——SVN安装配置篇
Subversion是一个自由,开源的版本控制系统.在Subversion管理下,文件和目录可以超越时空.Subversion将文件存放在中心版本库里.这个版本库很像一个普通的文件服务器,不同的是,它 ...