Problem:

Determine whether an integer is a palindrome. Do this without extra space.

简单的回文数,大一肯定有要求写过,不过从基础开始尝试吧。

Solution:

public class Solution {
public boolean isPalindrome(int x) {
int n=1;
int copyx=x;
if(x<0)return false;
if(x<10)return true;
while(x>=10){
x=x/10;
n++;
if(x<10)break;
} if(n%2==0)
{
while(copyx/(int)Math.pow(10,n-1)==copyx%10)
{
copyx=copyx%(int)Math.pow(10,n-1);
copyx=copyx/10;
// if(x==0)return true;
n=n-2;
if(n==0)return true; }
}
if(n%2==1)
{
while(copyx/(int)Math.pow(10,n-1)==copyx%10)
{
copyx=copyx%(int)Math.pow(10,n-1);
copyx=copyx/10;
// if(x==0)return true;
n=n-2;
if(n==1)return true; }
}
return false;
}
}

Leetcode 3——Palindrome Number(回文数)的更多相关文章

  1. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  2. [LeetCode]9. Palindrome Number回文数

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...

  3. 【LeetCode】Palindrome Number(回文数)

    这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...

  4. LeetCode Problem 9:Palindrome Number回文数

    描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

  5. 【LeetCode】9. Palindrome Number 回文数

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...

  6. [LeetCode] Prime Palindrome 质数回文数

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

  7. Palindrome Number 回文数

    判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出.     ...

  8. 【LeetCode】9 Palindrome Number 回文数判定

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

  9. 9. Palindrome Number 回文数的判断

    [抄题]: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the sam ...

随机推荐

  1. python version 2. required,which was not found in the registry 解决方案

    不能在注册表中识别python2.7 新建一个register.py 文件 import sys from _winreg import * # tweak as necessary version ...

  2. Exynos4412从SD卡启动的简单网络文件系统制作

    Exynos4412从SD卡启动的简单网络文件系统制作 1. 简介 嵌入式系统能够在开发板上正常运行,需要先进行系统配置,一个完整的嵌入式系统应该包含的几个部分::uboot,kernel,rootf ...

  3. 【BZOJ4071】八邻旁之桥(线段树)

    [BZOJ4071]八邻旁之桥(线段树) 题面 BZOJ权限题,洛谷链接 题解 既然\(k<=2\) 那么,突破口就在这里 分类讨论 ①\(k=1\) 这...不就是中位数吗.... 直接把所有 ...

  4. POJ3261:Milk Patterns

    题面 vjudge Sol 二分答案+分组,判断有没有一个组的后缀个数不小于 k 做法 # include <bits/stdc++.h> # define IL inline # def ...

  5. LightOJ1341 Aladdin and the Flying Carpet

    题意 给一对数字 a,b ,a是一个长方形的面积,问有多少种整数的边的组合可以组成面积为a的长方形,要求最短的边不得小于b 数据组数T<=4000, a,b<=10^12 Solution ...

  6. Js表单验证控件(使用方便,无需编码)-01使用说明

    演示地址:http://weishakeji.net/Utility/Verify/Index.htm    开源地址:https://github.com/weishakeji/Verify_Js ...

  7. sudo解决方案企业级应用实战

    visudo 编辑sudo配置文件 which  查找命令所在路径 例:touch /etc/oldboy.txt  没证件 sudo touch /etc/oldboy.txt  可以 内置命令没路 ...

  8. 如何通过Spring Boot配置动态数据源访问多个数据库

    之前写过一篇博客<Spring+Mybatis+Mysql搭建分布式数据库访问框架>描述如何通过Spring+Mybatis配置动态数据源访问多个数据库.但是之前的方案有一些限制(原博客中 ...

  9. 使用git工具快速push项目到github(精简)

    Dear Weber ,相信有很多刚开始接触前端的程序猿,在刚接触到git工具传项目到github上时会遇到一些问题,那么下面的话呢,我就整理一下一个大致的思路提供给大家参考: 工具:git (自行下 ...

  10. 利用XAMPP本地搭建WordPress博客

    现在越来越多的人利用WordPress搭建了自己的博客网站,我也是一样,但是还有一些人不知道怎么搭建WordPress网站的方法,因为怕弄 不好,所以也就没有花钱去做,所以这里我就讲讲怎么样利用XAM ...