看到这个题目的时候,首先不认识 Determine这个单词。英文不好没办法,查了下是确认的意思,然后不懂
palindrome这个单词, 查了下是回文的意思。

问题是 回文是个什么东西,官方解释: A palindrome is
a word, phrase, number,
or other sequence of characters which
reads the same backward or forward. 回文

尽管英文不好,可是这个英文解释还是看懂了的。意思就是从前读到后面和倒过来读是一样的。

然后又不理解后面那句 do this without extra space. 大概意思是实现的时候不能使用其它空间,事实上还是不懂。

不知道第二个方法里的,Math.pow()这种方法的调用算不算使用其它空间。

public class palindrome {

	//using with extra space
public static boolean check(int x){
String temp = Integer.toString(x);
boolean flag = true;
for(int i=0;i<temp.length()/2;i++){
char a = temp.charAt(i);
char b = temp.charAt(temp.length()-i-1);
if(a!=b){
flag = false;
}
}
return flag;
} //using without extra space
public static boolean check2(int x){
if(x<0)
return false;
int n=1;
int temp = x;
while(temp/10!=0){
temp=temp/10;
n++;
}
for(int i=0;i<n/2;i++){
int a = i;
int b = n-1-i;
if(getInt(x,a)!=getInt(x,b)){
return false;
}
}
return true;
}
// 比方 896698 这个数字。要获取百位,用896698除以100。得到8966然后取余10得到6。即为百位的数值
private static int getInt(int x,int i){
int a = (int) Math.pow(10, i);
return (x/a)%10;
}
}



Determine whether an integer is a palindrome. Do this without extra space.的更多相关文章

  1. [Algorithms] Determine if a string is a palindrome

    A palindrome is a string that reads the same forward and backward, for example, radar, toot, and mad ...

  2. 65. Reverse Integer && Palindrome Number

    Reverse Integer Reverse digits of an integer. Example1: x =  123, return  321 Example2: x = -123, re ...

  3. Palindrome Number & Reverse Integer

    Determine whether an integer is a palindrome. Do this without extra space. 分析:把一个数倒过来,然后看两个数是否相同. pu ...

  4. leetcode:Reverse Integer 及Palindrome Number

    Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...

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

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

  6. 【leetcode】Palindrome Number

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

  7. No.009:Palindrome Number

    问题: Determine whether an integer is a palindrome. Do this without extra space. 官方难度: Easy 翻译: 不使用额外空 ...

  8. Palindrome Number

    Determine whether an integer is a palindrome. Do this without extra space. public class Solution { p ...

  9. [Leetcode]Palindrome Number

    Determine whether an integer is a palindrome. Do this without extra space. 这题貌似解法挺多,直接用简单的把数倒置,没有考虑数 ...

随机推荐

  1. Linux网卡设置

    http://blog.chinaunix.net/uid-20149676-id-1733254.html

  2. literal控件的例子

    Literal的Mode属性,举例说明 这个属性的枚举值:PassThrough  Encode  Transform <%@ Page Language="C#" Auto ...

  3. MyEclipse2014不支持jre1.8吗

    myeclipse 2015才支持了java 8 也可以用Eclipse Kepler加插件的形式来支持java 8

  4. CSS中border-style的属性

    属性可能的值 值 描述 none 定义无边框. hidden 与 "none" 相同.不过应用于表时除外,对于表,hidden 用于解决边框冲突. dotted 定义点状边框.在大 ...

  5. Android Testing(1) 浅尝Android测试的奥秘

    ------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 仅供学习和交流使用,翻译不好勿喷,请只摘除不合适的地方 Testing The Android fram ...

  6. DataTable的属性与使用方式

    一.DataTable简介 (1)构造函数            DataTable()   不带参数初始化DataTable 类的新实例.            DataTable(string t ...

  7. ThinkPHP - 登录流程

    数据库: /* Navicat MySQL Data Transfer Source Server : 本地连接 Source Server Version : 50710 Source Host : ...

  8. [HDU 4842]--过河(dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4842 过河 Time Limit: 3000/1000 MS (Java/Others)    Mem ...

  9. [转] iOS (OC) 中 KVC 与 KVO 理解

    转自: http://magicalboy.com/kvc_and_kvo/ KVC 与 KVO 是 Objective C 的关键概念,个人认为必须理解的东西,下面是实例讲解. Key-Value ...

  10. MyEclipse8.5 中安装Spket插件

    MyEclipse8.5 中安装Spket插件 安装: 1. Myeclipse8.5安装和以前低版本有些不同(没有software updates). 点击help->Myeclipse Co ...