LintCode刷题小记491
题目:
判断一个正整数是不是回文数。
回文数的定义是,将这个数反转之后,得到的数仍然是同一个数。
样例:
11, 121, 1, 12321 这些是回文数。
23, 32, 1232 这些不是回文数。
分析:
回文数就是反转后和自身一样,可利用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的更多相关文章
- lintcode 刷题 by python 总结(1)
博主之前在学习 python 的数据结构与算法的基础知识,用的是<problem-solving-with-algorithms-and-data-structure-using-python& ...
- lintcode刷题笔记(一)
最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. L ...
- LintCode刷题笔记-- LongestCommonSquence
标签:动态规划 题目描述: Given two strings, find the longest common subsequence (LCS). Your code should return ...
- Atcoder刷题小记
1. 2019.4.27 agc016d 一道很坑的题. 首先判无解,求出异或值后排个序就可以. 然后直接让\(a_i\rightarrow b_i\)并查集维护,注意离散化和判重,答案加上联通块个数 ...
- lintcode 刷题 by python 部分链表题总结(2)
本篇博客对最近做的链表的算法题做个简单的小结,主要描述题目和提供解题思路,具体代码见我的 github:https://github.com/MUSK1881/lintcode-by-python 3 ...
- LintCode刷题指南:字符串处理(C++,Python)
题目:两个字符串是变位词 题目难度:简单 题目描述: 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 解题思路: C++:引入哈希的思维,这道题就 ...
- LintCode刷题笔记-- PaintHouse 1&2
标签: 动态规划 题目描述: There are a row of n houses, each house can be painted with one of the k colors. The ...
- LintCode刷题笔记-- Maximum Product Subarray
标签: 动态规划 描述: Find the contiguous subarray within an array (containing at least one number) which has ...
- LintCode刷题笔记-- Maximal Square
标签:动态规划 题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing a ...
随机推荐
- 738. Monotone Increasing Digits
Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...
- Multimap的初使用
之前不知道这个类型使用,在朋友的推荐下进行了个实际操作. 类似这种查询,我需要将他们归类拿出来,如果招以前那么拿的话可能要套挺多个循环的. 首先根据查询得到一个 List<Map<Stri ...
- 用python写个快排
快排过程比较简单就直接上代码了: #!/usr/bin/python3 def quik_sort(L, left, right): if left <= right: key = L[left ...
- Java中的Random()函数-----转载
Java中的Random()函数 (2013-01-24 21:01:04) 转载▼ 标签: java random 随机函数 杂谈 分类: Java 今天在做Java练习的时候注意到了Java里面的 ...
- Docker - 使用 Nexus3 搭设私有 NuGet 仓库
目录 前言 NuGet Nexus 私有仓库 说明 安装 Nexus 拉取 Nexus 镜像 运行 Nexus Nexus NuGet 仓库简单使用 Nexus 默认帐号 Repositories 上 ...
- KVO - 观察自定义属性值
1 . 声明属性&注册监听 { BOOL isOk; } [self addObserver:self forKeyPath:@"isOk" options:0 conte ...
- 关于运行robot framework 报错解决方法,ModuleNotFoundError: No module named 'robot'
报错: command: pybot.bat --argumentfile c:\users\76776\appdata\local\temp\RIDEiw0utf.d\argfile.txt --l ...
- Fast Matrix Operations UVA - 11992 线段树
题意翻译 有一个r行c列的全0矩阵,有以下三种操作. 1 X1 Y1 X2 Y2 v 子矩阵(X1,Y1,X2,Y2)的元素加v 2 X1 Y1 X2 Y2 v 子矩阵(X1,Y1,X2,Y2)的元素 ...
- Windows Server 2008 R2中IIS7.5配置完网站权限不足问题的解决办法:
Windows Server 2008 R2中IIS7.5配置完网站权限不足问题的解决办法:常见问题:HTTP 错误 500.0 - Internal Server Error无法显示页面,因为发生内 ...
- 12C GI + 11g DB 环境中PSU安装
环境说明: 12.1.0.2的GI集群,11.2.0.4的RAC数据库,需要安装最新的补丁. 补丁下载: 12.1.0.2 GI的PSU:11.2.0.4 DB的PSU:OJVM For 11.2.0 ...