【LeetCode9】Palindrome Number★
题目描述:

解题思路:
求回文数,并且要求不能使用额外的空间。思路很简单,算出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★的更多相关文章
- 【leetcode】Palindrome Number
题目简述: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could n ...
- 【leetcode】Palindrome Number (easy)
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- 【Leetcode009】Palindrome Number
问题链接:https://leetcode.com/problems/palindrome-number/#/description Question:Determine whether an int ...
- 【Leetcode】【Easy】Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. 判断一个整数是不是回文整数(例12321).不能使 ...
- 【Leetcode-easy】Palindrome Number
思路:除和求余 取得首位和末尾 比较是否相等. public boolean isPalindrome(int x){ if(x<0){ return false; } int div=1; w ...
- 【LeetCode】Palindrome Number(回文数)
这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...
- 【POJ2104】【HDU2665】K-th Number 主席树
[POJ2104][HDU2665]K-th Number Description You are working for Macrohard company in data structures d ...
- 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...
- 【CF932G】Palindrome Partition(回文树,动态规划)
[CF932G]Palindrome Partition(回文树,动态规划) 题面 CF 翻译: 给定一个串,把串分为偶数段 假设分为了\(s1,s2,s3....sk\) 求,满足\(s_1=s_k ...
随机推荐
- SurfaceView获取本地视频播放
1.定义 可以直接从内存或者DMA等硬件接口取得图像数据,是个非常重要的绘图容器. 它的特性是:可以在主线程之外的线程中向屏幕绘图上.这样可以避免画图任务繁重的时候造成主线程阻塞,从而提高了程序的反应 ...
- vue与原生混合开发
前段时间,做了一个混合开发的项目,主要是以vue框架开发h5页面,使用cordova作为中间沟通桥梁,实现了h5与安卓.iOS的混合开发,由于从事iOS开发,h5也是刚接触不久,很多深入原理还不太清楚 ...
- JSTL、JSTL核心标签库——流程处理标签
JSTL环境 JSTL是另一个标准规范,并非在JSP的规范中,所以必须另外下载JSTL实现. 要使用JSTL标签库,必须在JSP网页上使用taglib指示元素定义前置名称与uri参考.例如,引入JST ...
- TreeView失去焦点时亮显选中状态
Windows Form下设置属性即可. TreeView.HideSelection = false
- 【three.js练习程序】旋转物体自身
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- docker in all
docker vs hyper-v,vmware,xen,kvm docker host, docker container, docker engineen, docker image images ...
- Oracle EBS OPM 查询现有量
--查询现有量 --created by jenrry DECLARE p_inventory_item_id NUMBER := 231652; --NOT NULL p_organization_ ...
- SQL Server如何附加只有mdf的数据库文件
有时候SQL Server意外断电会导致SQL Server的ldf日志文件丢失或者损坏,这个时候你如果直接附加mdf文件到SQL Server会失败,这里提供一个方法可以还原只有mdf的数据库文件, ...
- CSS未知宽高元素水平垂直居中
方法一 :table.cell-table 思路:显示设置父元素为:table,子元素为:cell-table,这样就可以使用vertical-align: center,实现水平居中优点:父元素(p ...
- ping 命令 指定特定网卡 发送 ICMP 数据包
Windows : ping -S Linux : ping -I <device> -I interface interface is either an address, or an ...