Determine whether an integer is a palindrome. Do this without extra space.
看到这个题目的时候,首先不认识 Determine这个单词。英文不好没办法,查了下是确认的意思,然后不懂 palindrome这个单词, 查了下是回文的意思。
问题是 回文是个什么东西,官方解释: A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. 回文
尽管英文不好,可是这个英文解释还是看懂了的。意思就是从前读到后面和倒过来读是一样的。
然后又不理解后面那句 do this without extra space. 大概意思是实现的时候不能使用其它空间,事实上还是不懂。
不知道第二个方法里的,Math.pow()这种方法的调用算不算使用其它空间。
public class palindrome {//using with extra spacepublic static boolean check(int x){String temp = Integer.toString(x);boolean flag = true;for(int i=0;i<temp.length()/2;i++){char a = temp.charAt(i);char b = temp.charAt(temp.length()-i-1);if(a!=b){flag = false;}}return flag;}//using without extra spacepublic static boolean check2(int x){if(x<0)return false;int n=1;int temp = x;while(temp/10!=0){temp=temp/10;n++;}for(int i=0;i<n/2;i++){int a = i;int b = n-1-i;if(getInt(x,a)!=getInt(x,b)){return false;}}return true;}// 比方 896698 这个数字。要获取百位,用896698除以100。得到8966然后取余10得到6。即为百位的数值private static int getInt(int x,int i){int a = (int) Math.pow(10, i);return (x/a)%10;}
}
本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5154517.html,如需转载请自行联系原作者
Determine whether an integer is a palindrome. Do this without extra space.相关推荐
- [leetcode] Palindrome Number
2019独角兽企业重金招聘Python工程师标准>>> Determine whether an integer is a palindrome. Do this without e ...
- Leetcode: Palindrome Numbers
Determine whether an integer is a palindrome. Do this without extra space. 尝试用两头分别比较的方法,结果发现无法解决1000 ...
- 9. Palindrome Number
题目: Determine whether an integer is a palindrome. Do this without extra space. click to show spoiler ...
- 【LeetCode从零单排】No.9 Palindrome Number
题目 这道题是迄今为止最快通过的一道题,改了两次就过了,runtime一般(中等偏下,这点不太满意).Palindrome就是判断一个整数是否对称. Determine whether a ...
- 【Leetcode】Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. 思路:若使用[Leetcode]Reverse I ...
- [LeetCode] Palindrome Number Valid Palindrome - 回文系列问题
题目概述: Determine whether an integer is a palindrome. Do this without extra space. 题目分析: 判断数字是否是回文 例如1 ...
- [LeetCode] 9. Palindrome Number
传送门 Description Determine whether an integer is a palindrome. Do this without extra space. 思路 题意:判断输 ...
- LeetCode之Palindrome Number(回文数)
1.题目 Determine whether an integer is a palindrome. Do this without extra space. 2.代码实现 代码实现1 public ...
- LeetCode 9. Palindrome Number
题目: Determine whether an integer is a palindrome. Do this without extra space. 思路: 设置一个与x相等的num,因为要留 ...
最新文章
- 推荐!Sublime Text 最佳插件列表
- Git、TortoiseGit、GitHub、Gitee、GitLab 安装与入门使用
- Html代码seo优化最佳布局实例讲解
- Linux 查看文件指定行数 内容
- 基于Tensorflow实现多层感知机网络MLPs
- 《JAVA与模式》之观察者模式
- servlet中filter的的异步问题以及JSP与servlet配合时filter的注意
- C++ MathGL 二维数据绘图
- icmp基于tcp还是udp_imi -- 基于PHP协程应用开发框架,支持WebSocket,TCP,UDP应用开发...
- hadoop大数据架构
- BOSS直聘免费下载个人简历为PDF的方法
- flask框架之jinjia2模版语法详解
- Coinbase与华尔街的内幕故事
- 资源暂时不可用错误(Out of memery)完美解决方案
- 微信小程序怎么用? 老徐小程序!
- codeforces-1202C-WASD-string
- DIY人体红外报警器手机接收通知 防贼防盗防老王 物联网 智能家居
- jQuery WeUI v0.1.0 发布了 - 微信公众账号开发者的福音
- 互联网盈利模式研习笔记 1:流量变现
- java实现Word文档(doc、docx)在线查看功能(前台+后台)
热门文章
- windows10下使用virtualenv虚拟技术,管理多个python版本,多个项目包环境
- 车辆检测--DAVE: A Unified Framework for Fast Vehicle Detection and Annotation
- Java 使用线程池ThreadPool:newFixedThreadPool
- 笔记本电脑无线被禁用 是哪个服务器,无线网关,小编教你笔记本无线网络禁用后怎么开启...
- php自定义控件,小程序自定义组件的实现方法(代码)
- mysql配置日志老化配置_mysql中日志的配置与分析
- cad打印样式ctb丢失_CAD制图软件中如何设置CAD打印样式表(CTB)?
- pandas describe函数_PANDAS: 新手教程 一
- 真厉害用python只要50行代码爬取黑丝美眉纯欲高清图
- 5秒到1秒,记一次效果“非常”显著的性能优化