Easy 9题 Palindrome Number
来源:互联网 发布:软件外包人员管理 编辑:程序博客网 时间:2024/05/17 06:37
Question:
Determine whether an integer is a palindrome. Do this without extra space.
Solution:
调试半天。。。但居然过了61%
public class Solution { public boolean isPalindrome(int x) { if(x<0) return false; if(x==0) return true; int tmp=x; int count=1; while(tmp/10!=0) { tmp=tmp/10; count++; } for(int i=1,j=count;i<j;i++) { int tmp_1=(int) (x%(Math.pow(10,1))); int tmp_2=(int) (x/(Math.pow(10,j-1))); //测试前面有几个零 int ii=1; int jj=j-2; int cou=1; while((int)(x/(Math.pow(10,jj)))==Math.pow(10,ii)) { ii++; jj--; cou++; } int tmpp=(int) (x-tmp_2*Math.pow(10,j-1)-tmp_1); if((int) tmpp%Math.pow(10,cou)!=0) return false; x= (int) (tmpp/Math.pow(10,cou)); if(tmp_1!=tmp_2) return false; j=j-cou*2; } return true; }}
discuss上的解法
if(x<0||(x!=0&&x%10==0)) return false; int rev=0; while(x>rev) { rev=rev*10+x%10; x=x/10; } return (x==rev||x==rev/10);
0 0
- Easy 9题 Palindrome Number
- [Leetcode 9, Easy] Palindrome Number
- 【LeetCode】(9)Palindrome Number(Easy)
- <LeetCode><Easy> 9 Palindrome Number
- LeetCode #9 - Palindrome Number - Easy
- LeetCode-9-Palindrome Number(Number)-Easy
- Easy 3 Palindrome Number(9)
- LeetCode OJ 9 Palindrome Number [easy]
- 9. Palindrome Number (Easy)
- 3.[easy] Palindrome Number
- 9. Palindrome Number [easy] (Python)
- LeetCode:9.Palindrome Number[Easy]
- LeetCode-Easy-Java-Palindrome Number
- LeetCode 9 Palindrome Number (easy)——python
- Easy-题目35:9. Palindrome Number
- Leetcode 9. Palindrome Number (Easy) (cpp)
- 算法第三周Palindrome Number[easy]
- (算法分析Week5)Palindrome Number[Easy]
- Android-RecyclerView 实现步骤
- wireshark 与计算机网络额不得不说的秘密---->16位进制面板(解析器)的介绍
- Linux 常用命令使用——登陆退出Linux系统
- TextView、EditText 怎样设置后缀为 .otf 原生文件 的文字样式
- CDH(Cloudera)与hadoop(Apache)对比
- Easy 9题 Palindrome Number
- 毕业生关于签约、毁约和存档的介绍---一个很好的科普
- Android-TableLayout例子
- 趣味网站、趣味应用
- bootstrap点击弹框
- filesize的缓存问题
- 汇编语言的基础总结1
- 循序渐进学习Linux之教您软件如何配置
- Java-Mina Server使用步骤