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

分析:把一个数倒过来,然后看两个数是否相同。

 public class Solution {
public boolean isPalindrome(int x) {
if (x < ) {
return false;
}
long palindromeX = , inputX = x;
while (x > ) {
palindromeX = palindromeX * + (x % );
x = x / ;
}
return palindromeX == inputX;
}
}

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

 public class Solution {
public int reverse(int x) {
boolean isPositive = true; if (x < ) {
x = -x;
isPositive = false;
} long reversedValue = ;
while (x != ) {
reversedValue = reversedValue * + x % ;
x /= ;
}
if (Math.abs(reversedValue) > Integer.MAX_VALUE) return ; return isPositive ? (int)reversedValue : (int)(-reversedValue);
}
}

Palindrome Number & Reverse Integer的更多相关文章

  1. 65. Reverse Integer && Palindrome Number

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

  2. leetcode:Reverse Integer 及Palindrome Number

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

  3. Reverse Integer - Palindrome Number - 简单模拟

    第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断.溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较. ...

  4. 【LeetCode】9 & 234 & 206 - Palindrome Number & Palindrome Linked List & Reverse Linked List

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

  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. 9. Palindrome Number

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

  7. No.009 Palindrome Number

    9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...

  8. Leetcode 9. Palindrome Number(判断回文数字)

    Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...

  9. leetcode 9 Palindrome Number 回文数

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

随机推荐

  1. win10默认壁纸位置

    win10默认壁纸的位置... --------- win10默认壁纸位置C:\Windows\Web\4K\Wallpaper\Windows win10 默认 锁屏壁纸C:\Windows\Web ...

  2. 3D转换(位置)+过渡+透视

    效果如图: html代码: <div class="door"> <div class="in"><div> </di ...

  3. golang rpc介绍

    rpc包提供了通过网络或其他I/O连接对一个对象的导出方法的访问.服务端注册一个对象,使它作为一个服务被暴露,服务的名字是该对象的类型名.注册之后,对象的导出方法就可以被远程访问.服务端可以注册多个不 ...

  4. Centos7使用kubeadm 安装多主高可用kubernets:v.1.11集群

    实验环境介绍: 本次实验环境是5个节点 3台master 2台node节点: k8smaster01 192.168.111.128 软件:etcd k8smaster haproxy keepali ...

  5. JavaEE之JDBC编程[详解]

    1.数据库简介 数据库(DB,Data Base ) 数据库管理系统(DBMS,Data Base Management System) 关系型数据库(RDB) 关系型数据库管理系统(RDBMS) S ...

  6. java使用google开源工具实现图片压缩【转】

    jar包名 import net.coobird.thumbnailator.Thumbnails; import net.coobird.thumbnailator.geometry.Positio ...

  7. ZOJ - 1610 Count the Colors(线段树区间更新)

    https://cn.vjudge.net/problem/ZOJ-1610 题意 给一个n,代表n次操作,接下来每次操作表示把[l,r]区间的线段涂成k的颜色其中,l,r,k的范围都是0到8000. ...

  8. PHP7 学习笔记(十二)gRPC

    GitHub:https://github.com/grpc/grpc/tree/master/src/php 环境:Linux + php7 1.安装grpc pecl install grpc 编 ...

  9. mysql表基本查询

    第一节 -- or # 单行注释/***多行注释*/ -- c创建数据库examCREATE DATABASE exam; USE exam; /*创建部门表*/CREATE TABLE dept( ...

  10. idea整合SVN以及SVN的使用

    idea整合SVN以及SVN的使用: 1:下载插件: 运行并安装: 安装后的目录: 2-1 打开bin目录 :复制svn.exe的文件路径: 2:打开IDEA的File-->setting: o ...