题目:

  判断一个正整数是不是回文数。

  回文数的定义是,将这个数反转之后,得到的数仍然是同一个数。

样例:

  11121112321 这些是回文数。

  23321232 这些不是回文数。

分析:

  回文数就是反转后和自身一样,可利用java中StringBuffer中reverse()这一函数进行操作。

  下面给出代码:

 public class Solution {
/**
* @param num a positive number
* @return true if it's a palindrome or false
*/
public boolean palindromeNumber(int num) {
String str = Integer.toString(num); //将int型转为String型
StringBuffer sb = new StringBuffer(str); //构造StringBuffer对象
boolean x = false;
if(sb.reverse().toString().equals(str)){ //sb对象反转变为String对象再与原字符串比较
x = true;
}
else {
x = false;
}
return x;
}
}

    

LintCode刷题小记491的更多相关文章

  1. lintcode 刷题 by python 总结(1)

    博主之前在学习 python 的数据结构与算法的基础知识,用的是<problem-solving-with-algorithms-and-data-structure-using-python& ...

  2. lintcode刷题笔记(一)

    最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. L ...

  3. LintCode刷题笔记-- LongestCommonSquence

    标签:动态规划 题目描述: Given two strings, find the longest common subsequence (LCS). Your code should return ...

  4. Atcoder刷题小记

    1. 2019.4.27 agc016d 一道很坑的题. 首先判无解,求出异或值后排个序就可以. 然后直接让\(a_i\rightarrow b_i\)并查集维护,注意离散化和判重,答案加上联通块个数 ...

  5. lintcode 刷题 by python 部分链表题总结(2)

    本篇博客对最近做的链表的算法题做个简单的小结,主要描述题目和提供解题思路,具体代码见我的 github:https://github.com/MUSK1881/lintcode-by-python 3 ...

  6. LintCode刷题指南:字符串处理(C++,Python)

    题目:两个字符串是变位词 题目难度:简单 题目描述: 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 解题思路: C++:引入哈希的思维,这道题就 ...

  7. LintCode刷题笔记-- PaintHouse 1&2

    标签: 动态规划 题目描述: There are a row of n houses, each house can be painted with one of the k colors. The ...

  8. LintCode刷题笔记-- Maximum Product Subarray

    标签: 动态规划 描述: Find the contiguous subarray within an array (containing at least one number) which has ...

  9. LintCode刷题笔记-- Maximal Square

    标签:动态规划 题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing a ...

随机推荐

  1. VINS-Mono Installation

    Prerequisites 1.1 ** Ubuntu 16.04, ROS Kinetic ** sudo apt-get install ros-kinetic-cv-bridge ros-kin ...

  2. Java面向对象之多态(成员访问特点) 入门实例

    一.基础概念 多态的调用方式在子父类中的特殊体现. 1.访问成员变量特点: 当子父类中出现同名成员变量时. 多态调用时,编译和运行都参考引用型变量所属的类中的成员变量. 即编译和运行看等号的左边. 2 ...

  3. C# 精准计时之 QueryPerformanceCounter QueryPerformanceFrequency用法

    C# 用法: public static class QueryPerformanceMethd { [DllImport("kernel32.dll")] public exte ...

  4. behave 测试框架,了解一下

    # behave测试框架 [behave](https://pythonhosted.org/behave/)是python的1个bdd测试框架实现. ### 安装 ```pip install be ...

  5. TX2 Clone

    由于给TX2配置了很多的开发环境,也修改了一些驱动,想将这些环境能够完整的迁移到一块bare TX2,于是尝试了clone的方法. 这种方法的优点是: 确保了移植的TX2 与已经配置好的环境是一致的: ...

  6. x-boot

    https://github.com/Exrick/x-boot-front https://gitee.com/Exrick/x-boot

  7. abp + angular 前端使用 hash ,登录界面不跳转问题

    abp 项目默认的路由没有使用hash,这会导致手动刷新浏览器时,页面404错误: 解决方法网上很多,就是在路由里添加一个{useHash: true},就行了. #用Hash带来的新问题# abp框 ...

  8. 使用xcode测量ios8.1机型时的项目兼容问题

    打开xcode,创建一个新项目 点击左上角的三角形打开模拟器,打开模拟器中的safari,把项目链接输入,即可测试 下面为切换机型的方法:

  9. [转] docker save与docker export的区别

    [From]http://cnodejs.org/topic/59a2304f7aeedce818249eeb 很久没有写博客了,坟头草都长了老高了.写博客要靠惯性,一旦停下来时间长了,就很难再坚持下 ...

  10. windos下安装mongodb

    一.下载 1. www.mongodb.com/download-center#community2.根据电脑系统下载对应的版本,3.选择zip(解压版本)/msi安装版本4.本文是用的msi(安装版 ...