LeetCode 9. Palindrome Number(回文数)
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
- Input: 121
- Output: true
Example 2:
- Input: -121
- Output: false
- Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
- Input: 10
- Output: false
- Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Follow up:
Coud you solve it without converting the integer to a string?
- public boolean isPalindrome(int x) {
- int[] nums=new int[32];
- int i=0;
- if(x<0)//负数或 最后一位为0(后半句不严谨,单独0是对称的)
- return false;
- while(x/10>0){
- nums[i]=x%10;
- i++;
- x=x/10;
- }
- nums[i]=x%10;
- int len=0;
- for(i=31;i>=0;i--){
- if(nums[i]>0){
- len=i;//数字位数
- break;
- }
- }
- for(i=0;i<=len/2;i++){
- if(nums[i]!=nums[len-i])
- return false;
- }
- return true;
- }
LeetCode 9. Palindrome Number(回文数)的更多相关文章
- leetcode 9 Palindrome Number 回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- Leetcode 3——Palindrome Number(回文数)
Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...
- [LeetCode]9. Palindrome Number回文数
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...
- 【LeetCode】Palindrome Number(回文数)
这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...
- LeetCode Problem 9:Palindrome Number回文数
描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
- 【LeetCode】9. Palindrome Number 回文数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...
- [LeetCode] Prime Palindrome 质数回文数
Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...
- Palindrome Number 回文数
判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出. ...
- 【LeetCode】9 Palindrome Number 回文数判定
题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...
- 9. Palindrome Number 回文数的判断
[抄题]: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the sam ...
随机推荐
- 【转】Java学习---Java中volatile关键字实现原理
[原文]https://www.toutiao.com/i6592879392400081412/ 前言 我们知道volatile关键字的作用是保证变量在多线程之间的可见性,它是java.util.c ...
- 56_实现类似spring的可配置的AOP框架
> config.properties 配置文件 key=类名 > BeanFactory Bean工厂,负责得到bean getBean("xxx") &g ...
- git 学习汇总
生成gitignore 文件: https://gitignore.io/ git 版本回退 git reset --hard HEAD^ 上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然 ...
- Alpha冲刺报告(6/12)(麻瓜制造者)
今日已完成 邓弘立: 看github上的开源库 确定了几个对UI改进有帮助的第三方库 符天愉: 部署了用户修改信息,修改头像的接口,并且完成两个接口的api文档,复习了PHP的无限分类来实现商品的发布 ...
- 死磕nginx系列--nginx 限流配置
限流算法 令牌桶算法 算法思想是: 令牌以固定速率产生,并缓存到令牌桶中: 令牌桶放满时,多余的令牌被丢弃: 请求要消耗等比例的令牌才能被处理: 令牌不够时,请求被缓存. 漏桶算法 算法思想是: 水( ...
- 【转】PHP----JS相互调用
JS调用PHP 1.取值: 执行html,得到一个弹窗,提示:I from PHP <script type="text/javascript" src="http ...
- trufflesuite/truffle-hdwallet-provider
https://github.com/trufflesuite/truffle-hdwallet-provider/blob/master/index.js 实现代码 truffle-hdwallet ...
- python+requests实现接口测试 - cookies的使用 (转载)
出自:https://www.cnblogs.com/nizhihong/p/6699492.html 在很多时候,发送请求后,服务端会对发送请求方进行身份识别,如果请求中缺少识别信息或存在错误的识别 ...
- linux固定ip地址
最近自己搭jenkins发现ifconfig出来ip老是变来变去决定固定服务ip,原来配置: [root@bogon bin]# cat /etc/sysconfig/network-scripts/ ...
- $Simpson$积分入门
\(\rm{0x01}\) 前言 首先阐明一点,自适应辛普森算法(\(\rm{Adaptive ~Simpson's~ rule}\) )是一类近似算法(\(\rm{Approximation ~al ...