【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 ...
随机推荐
- 通过sql的DMV查看数据库使用状态
--数据库隔离级别 读未提交 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; --查找每次执行时引发I/O最多的前10位的查询 total_logi ...
- maven一模块字段调用另一个模块数据生成下拉框
店铺运营数据录入表实现的下拉框实现 从片区管理中提取分区数据,在招商管理(MIS)模块中获取并以下拉框的形式展现 ctrl类: 1.首先在ctrl类注入需提取另一模块字段的serviceclient接 ...
- Android--动态改变ImageView的亮度
//改变图片的亮度方法 0--原样 >0---调亮 <0---调暗 private void changeLight(ImageView imageView, int brightness ...
- 数组、ArrayList、链表、LinkedList
数组 数组 数组类型 不可重复 无序(线性查找) 可重复(找到第一个即可) 无序(线性查找) 不可重复 有序(二分查找) 可重复(找到第一个即可) 有序(二分查找) 插入 O(N) O(1) O( ...
- Djang之Model操作
Django之Model操作 一.字段 1.字段列表: AutoField(Field) - int自增列,必须填入参数 primary_key=True BigAutoField(AutoField ...
- MySQL——通过EXPLAIN分析SQL的执行计划
在MySQL中,我们可以通过EXPLAIN命令获取MySQL如何执行SELECT语句的信息,包括在SELECT语句执行过程中表如何连接和连接的顺序. 下面分别对EXPLAIN命令结果的每一列进行说明: ...
- pytest进阶
参考文章 使用 pytest pytest 这个 库是一个第三方库,严格来说,它的设计思路不属于 xUnit 系列.但它使用起来比较方便,同时他又兼容 unittest 的用例:用 unittest ...
- ubuntu下编译qt5
编译步骤参考: http://doc.qt.io/qt-5/linux.html 我们使用源代码和编译目录分离的编译方式, 这样避免编译主机系统和目标系统间的独立. 参考: Qt Configure ...
- SQL Server中事务transaction如果没写在try catch中,就算中间语句报错还是会提交
假如我们数据库中有两张表Person和Book Person表: CREATE TABLE [dbo].[Person]( ,) NOT NULL, ) NULL, ) NULL, [CreateTi ...
- AndroidManifest 配置主活动
在activity标签中写如下代码: <activity android:name=".MainActivity" android:label="This is M ...