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的更多相关文章

  1. Leetcode 题目整理-3 Palindrome Number & Roman to Integer

    9. Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. clic ...

  2. leetCode练题——9. Palindrome Number

    1.题目 9. Palindrome Number   Determine whether an integer is a palindrome. An integer is a palindrome ...

  3. 【LeetCode算法-9】Palindrome Number

    LeetCode第9题 Determine whether an integer is a palindrome. An integer is a palindrome when it reads t ...

  4. 【LeetCode】9、Palindrome Number(回文数)

    题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...

  5. LeetCode(9)Palindrome Number

    题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...

  6. 【leetcode❤python】 9. Palindrome Number

    #回文数#Method1:将整数转置和原数比较,一样就是回文数:负数不是回文数#这里反转整数时不需要考虑溢出,但不代表如果是C/C++等语言也不需要考虑class Solution(object):  ...

  7. Palindrome Number - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Palindrome Number - LeetCode 注意点 负数肯定是要return false的 数字的位数要分奇数和偶数两种情况 解法 解法一: ...

  8. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  9. leetcode bug & 9. Palindrome Number

    leetcode bug & 9. Palindrome Number bug shit bug "use strict"; /** * * @author xgqfrms ...

随机推荐

  1. 【bzoj1565】[NOI2009]植物大战僵尸

    1565: [NOI2009]植物大战僵尸 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2164  Solved: 1001[Submit][Stat ...

  2. dataTable写入数据库(大数据写入)

    例1: connectionStr,链接字符串dataTableName, 数据库中对应表名sourceDataTable DataTable 要写入数据库的DataTable字段要和表一致 publ ...

  3. 使用Apache IO库操作IO与文件

    --------------siwuxie095                         首先到 Apache官网 下载相关的库文件     Apache官网:http://www.apach ...

  4. 383. Ransom Note 在字典数组中查找笔记数组

    [抄题]: Given an arbitrary ransom note string and another string containing letters from all the magaz ...

  5. dynamic和匿名类和var的混合使用 没提示照样点

    using System;using System.Collections;using System.Collections.Generic;using System.Linq;using Syste ...

  6. getchar() getch() getche() gets() puts() scanf()的用法及区别

    getchar() putchar(ch) scanf()   头文件stdio.h getch() getche()   头文件conio.h gets() puts()    头文件stdio.h ...

  7. 如何确定tabcontrol哪一页码是活跃页???

    tabControl1.SelectedIndex属性 显示了现在显示的是哪一页码内的控件.

  8. MyEclipse2014配置2.5版本的struts2

    原创 配置struts2一般来说需要以下步骤: 将项目所需要的Jar包导入项目webRoot/WEB-INF/lib下(包不追求多,容易导致冲突或者其他问题,需要多少导入多少) 配置struts.xm ...

  9. Spring:配置文件

    首先是bean.xml,配置所有的bean,一般也叫applicationContext.xml,应用程序上下文.示例: <?xml version="1.0" encodi ...

  10. java类创建时里面成员执行的先后顺序

    静态代码块在类第一次使用的时候执行一次,在构造函数执行之前执行.只要用到类,哪怕new对象(比如只声明变量)也会被执行,且只执行一次.一般用于对类进行初始化. 先执行静态代码块,静态成员(谁在前就先执 ...