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. Educational Codeforces Round37 E - Connected Components?

    #include <algorithm> #include <cstdio> #include <iostream> #include <queue> ...

  2. “玲珑杯”ACM比赛 Round #4 B Best couple

    一眼的KM,但是建图的时候记得不用的点设为0,点少的一边补齐,这个非常重要,因为KM追求完全匹配,如果无法完全匹配会非常慢 #include<bits/stdc++.h> using na ...

  3. hdu5904 LCIS

    这题惩罚我这种经常不管常数的懒人 直接 1e6 TLE 如果1e5对数组枚举过 诶其实很想吐槽些伤心事,但是还是不想在博客上吐口水 不管今年比赛结果如何 请享受比赛 #include<bits/ ...

  4. 网络协议笔记-网络层-ARP协议

    [2-地址解析协议ARP] [2.1-基本概念] 地址解析协议ARP的作用是根据主机的IP地址,找出该主机的硬件地址. [2.2-为什么要使用ARP] 在数据传输过程中,网络层使用的IP地址,但是在实 ...

  5. 描述下@Component,@Repository,@Service,@Scope,@Autowired,@Inject,@Value标记的作用

    1.@Component为通用注解. 2.@Repository为持久层组件注解. 3.@Service为业务层组件注解. 4.@Scope为Bean的作用域注解. 5.@Autowired,@Inj ...

  6. I/HwPointEventFilter: do not support AFT because of no config

    I/HwPointEventFilter: do not support AFT because of no config 这是华为对系统做了修改,默认不打印日志,要改配置 在拨号界面输入:以下进入工 ...

  7. UVA10294 Arif in Dhaka (群论,Polya定理)

    UVA10294 Arif in Dhaka (群论,Polya定理) 题意 : 给你一个长为\(n\)的项链和手镯,每个珠子有\(m\)种颜色. 两个手镯定义为相同,即它们通过翻转和旋转得到一样的手 ...

  8. [UVAlive4297]First Knight

    题面在这里 题意 给定一个\(n\times m\)的格网,从\((1,1)\)出发,每一格\((i,j)\)往上下左右移动的概率已经给出,询问到达\((n,m)\)的期望步数 数据范围 \[n,m\ ...

  9. freemind中内容变成html转义字符解决方法

    在使用freemind的时候,没有正常关闭,导致原来的内容变成下面这样: <html> <body> <p> <b>查询所有</b> < ...

  10. Cassandra配置多节点集群以及使用雅虎YCSB压测Cassandra 3.11

    这几天在搭Cassandra集群以及对Cassandra的性能测试,步骤还挺多,记录一下. 关于Caaandra在服务器上配置多节点集群,可以参考一下文章: http://blog.csdn.net/ ...