题目描述:

解题思路:

  求回文数,并且要求不能使用额外的空间。思路很简单,算出x的倒置数reverse,比较reverse是否和x相等就行了。

Java代码:

 public class LeetCode9 {
public static void main(String[] args) {
int x=1221;
System.out.println(x+"是否是回文数:"+new Solution2().isPalindrome(x));
}
}
class Solution2 {
public boolean isPalindrome(int x) {
if(x<0) return false;
int reverse=0,temp=x;
while(temp>0){
reverse=reverse*10+temp%10;
temp/=10;
}
return (reverse==x);
}
}

程序结果:

【LeetCode9】Palindrome Number★的更多相关文章

  1. 【leetcode】Palindrome Number

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

  2. 【leetcode】Palindrome Number (easy)

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

  3. 【Leetcode009】Palindrome Number

    问题链接:https://leetcode.com/problems/palindrome-number/#/description Question:Determine whether an int ...

  4. 【Leetcode】【Easy】Palindrome Number

    Determine whether an integer is a palindrome. Do this without extra space. 判断一个整数是不是回文整数(例12321).不能使 ...

  5. 【Leetcode-easy】Palindrome Number

    思路:除和求余 取得首位和末尾 比较是否相等. public boolean isPalindrome(int x){ if(x<0){ return false; } int div=1; w ...

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

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

  7. 【POJ2104】【HDU2665】K-th Number 主席树

    [POJ2104][HDU2665]K-th Number Description You are working for Macrohard company in data structures d ...

  8. 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)

    [SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...

  9. 【CF932G】Palindrome Partition(回文树,动态规划)

    [CF932G]Palindrome Partition(回文树,动态规划) 题面 CF 翻译: 给定一个串,把串分为偶数段 假设分为了\(s1,s2,s3....sk\) 求,满足\(s_1=s_k ...

随机推荐

  1. Intellij idea Cannot start internal HTTP server.

    错误提示:Cannot start internal HTTP server. Git integration, JavaScript debugger and LiveEdit may operat ...

  2. flex兼容性问题

    flex在众多手机浏览器上的兼容方案(亲测华为手机自带浏览器) 如果项目使用构建工具,可加autoprefixer来处理,[autoprefixer使用指南] 纯手写css兼容代码,需给每个使用的属性 ...

  3. js 事件委托代理

    在优化网页性能的技巧当中,对DOM的优化是必不可少的.这其中就涉及到了javascript对DOM的频繁操作.比如响应用户操作的事件.一般情况下,如果是稍微初级一点的前端程序员,在拿到项目的时候,对待 ...

  4. kvm 创建新虚拟机命virt-install 使用说明

    virt-install 命令说明 1.命令作用      建立(provision)新虚拟机   2.语法   virt-install [选项]... 3.说明(DESCRIPTION)   vi ...

  5. OSGI企业应用开发(四)使用Blueprint整合Spring框架(一)

    上篇文章中介绍了如何使用独立的Equinox发行包搭建OSGI运行环境,而不是依赖与具体的Eclipse基础开发工具,本文开始介绍如何使用Blueprint將Spring框架整合到OSGI中. 一.开 ...

  6. ActiveReports 报表应用教程 (11)---交互式报表之文档目录

    通过文档目录,用户可以非常清晰的查看报表数据结构,并能方便地跳转到指定的章节,最终还可以将报表导出为PDF等格式的文件.本文以2012年各月产品销售分类汇总报表为例,演示如何在葡萄城ActiveRep ...

  7. HttpWatch HttpWatch时间表(HttpWatch Time Charts)

    HttpWatch时间表(HttpWatch Time Charts) by:授客 QQ:1033553122 截图 说明 页面事件线(Page Event Lines)

  8. Oracle 用户、角色管理简介

    Oracle 用户.角色管理简介 by:授客 QQ:1033553122 创建用户 形式1:创建名为testacc2的用户 CREATE USER testacc2 IDENTIFIED BY abc ...

  9. Laravel安装教程

    1.Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length() 报这个错是因为Apache/bin目录下 l ...

  10. oracle EBS rtf报表不能输出模板样式

    1.需要定义中文的数据定义 2.缺少文件 cd $ADMIN_SCRIPTS_HOME prefs.ora 3.查看文档  文档 ID 1059712.1 (1)请求模版显示不出来 解决:模版定义中模 ...