LeetCode记录之9——Palindrome Number
LeetCode真是个好东西,本来闲了一下午不想看书,感觉太荒废时间了就来刷一道题。能力有限,先把easy的题目给刷完。
Determine whether an integer is a palindrome. Do this without extra space.
确定一个整数是否是回文。 做这个没有额外的空间。
这道题毕竟是easy级别的,花了大概5分钟就写出来了。我的思路就是判断回文要首尾一一对照么,如果把int转换成string类型的话比较字符就方便多了。
class Solution {
public boolean isPalindrome(int x) {
boolean isAbove=true;
if(x<0){
return false;
}
String num=x+"";
int length=num.length();
for(int i=0;i<length/2;i++){
if(num.charAt(i)!=num.charAt(length-i-1))
return false;
}
return true;
}
}
LeetCode记录之9——Palindrome Number的更多相关文章
- Leetcode 题目整理-3 Palindrome Number & Roman to Integer
9. Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. clic ...
- leetCode练题——9. Palindrome Number
1.题目 9. Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome ...
- 【LeetCode算法-9】Palindrome Number
LeetCode第9题 Determine whether an integer is a palindrome. An integer is a palindrome when it reads t ...
- 【LeetCode】9、Palindrome Number(回文数)
题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...
- LeetCode(9)Palindrome Number
题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...
- 【leetcode❤python】 9. Palindrome Number
#回文数#Method1:将整数转置和原数比较,一样就是回文数:负数不是回文数#这里反转整数时不需要考虑溢出,但不代表如果是C/C++等语言也不需要考虑class Solution(object): ...
- Palindrome Number - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Palindrome Number - LeetCode 注意点 负数肯定是要return false的 数字的位数要分奇数和偶数两种情况 解法 解法一: ...
- 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...
- leetcode bug & 9. Palindrome Number
leetcode bug & 9. Palindrome Number bug shit bug "use strict"; /** * * @author xgqfrms ...
随机推荐
- Oracle树查询,start with connect by prior 递归查询用法(转载)
本人觉得这个写的真不错,实用性强,就转载过来了 这个子句主要是用于B树结构类型的数据递归查询,给出B树结构类型中的任意一个结点,遍历其最终父结点或者子结点. 先看原始数据: 1 create tabl ...
- Base -快捷键|通配符|特殊符号|输出(正确与错误的保存)
curl + a 移动光标到行首. curl +e 移动光标到行尾. curl +k 剪切光标所在位置到行末的字符. curl+u 剪切光标所在位置到行首的字符. curl +y ...
- linux c 获取系统时间
#include <time.h> main() { time_t timep; time (&timep); printf(“%s”,asctime(gmtime(&ti ...
- list 的扩展
数据挖掘中会遇到添加多个新的特征s,对一个feature = list()来说, 除了可以用 feature.append('xx') # 在尾部添加一个特征 feature.extend(['xx' ...
- SP1557 GSS2 - Can you answer these queries II
一开始看不懂题解,看懂了题解之后觉得还是挺妙的. 好多题解里都提到了HH的项链,但是我觉得关系并不大啊…… 先把所有询问离线下来按照右端点排序,按照询问的要求一个一个加入数字,怎么加入数字,我们设计一 ...
- [GO]随机生成切片元素并使用冒泡排序方式进行排序
package main import ( "math/rand" "time" "fmt" ) func ButtleData(s []i ...
- 编写高质量代码改善C#程序的157个建议——建议58:用抛出异常代替返回错误代码
建议58:用抛出异常代替返回错误代码 CLR异常机制的优点: 正常控制流会被立即中止,无效值或状态不会在系统中继续传播. 提供了统一的处理错误的方法. 提供了在构造函数.操作符重载及属性中报告异常的遍 ...
- 转换汉子首字母类 CreatChinaSpell
public class CreatChinaSpell { public static string GetChineseFirstChar(string chineseStr) { StringB ...
- 6步完成压力测试工具Locust部署和使用
1,准备安装python,安装过程略 已安装的,查看安装目录: cmd输入where Python 2,pip安装locust 1.进入python所在目录,如果没有配置环境变量,需要进入到C:\Us ...
- Nginx conf基本配置
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debu ...