LeetCode算法入门- Palindrome Number-day2
LeetCode算法入门- Palindrome Number-day2
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.
方法一:
将int类型x进行反转,如果反转之后和之前的数字一样,说明是回文,否则不是(记得排除负数的)
class Solution {public boolean isPalindrome(int x) {if(x < 0) return false;//这里是将int类型X进行反转int reverse = 0;int old = x;while(x != 0){reverse = reverse * 10 + x % 10;x = x / 10;}return reverse == old;}
}
LeetCode算法入门- Palindrome Number-day2相关推荐
- LeetCode算法入门- Multiply Strings -day18
LeetCode算法入门- Multiply Strings -day18 题目介绍 Given two non-negative integers num1 and num2 represented ...
- LeetCode算法入门- Compare Version Numbers -day14
LeetCode算法入门- Compare Version Numbers -day14 题目描述: Compare two version numbers version1 and version2 ...
- LeetCode算法入门- Roman to Integer Integer to Roman -day8
LeetCode算法入门- Roman to Integer -day8 Roman to Integer: 题目描述: Roman numerals are represented by seven ...
- LeetCode算法入门- String to Integer (atoi)-day7
LeetCode算法入门- String to Integer (atoi)-day7 String to Integer (atoi): Implement atoi which converts ...
- LeetCode算法入门- Add Two Numbers-day3
LeetCode算法入门- Add Two Numbers-day3 Add Two Numbers You are given two non-empty linked lists represen ...
- LeetCode算法入门- Implement strStr() -day22
LeetCode算法入门- Implement strStr() -day22 题目描述 Implement strStr(). Return the index of the first occur ...
- LeetCode算法入门- Remove Duplicates from Sorted Array -day21
LeetCode算法入门- Remove Duplicates from Sorted Array -day21 题目描述 Given a sorted array nums, remove the ...
- LeetCode算法入门- Remove Element -day20
LeetCode算法入门- Remove Element -day20 1. 题目描述 Given an array nums and a value val, remove all instance ...
- LeetCode算法入门- Search Insert Position -day19
LeetCode算法入门- Search Insert Position -day19 题目描述 Given a sorted array and a target value, return the ...
最新文章
- ActiveMQ死信队列使用
- linux 自动ping脚本,linux上ping脚本及zabbix3.xx上自动发现
- MySQL输入密码后闪退
- java 注解 属性 类型_跟光磊学Java开发-Java注解
- python接口测试实战_Python接口测试实战5(下) - RESTful、Web Service及Mock Server
- leetcode42 --- trap
- 数列求和(洛谷P5745题题解,C++语言描述)
- 修复完整运营版-苹果cms影视电影小程序源码
- 每天一道算法题(13)——使用递归颠倒栈
- Mybatis中resultMap的作用-解决实体类属性名和数据库字段不一致
- src refspec main does not match any
- showDialog 必须Stateful
- 个性化互联网时代,互联网营销
- EXT.NET GridPanel默认选中多行
- 浪漫爱心表白网页模板
- 贪心算法(贪婪算法)
- 神经网络模型学习笔记(ANN,BPNN)
- java P1195 口袋的天空
- 自定义ckeditor图片上传插件
- 记录一下Ubuntu下安装Docker遇到的坑
热门文章
- 面试官 | 说一下 JVM 常用参数有哪些?
- Navicat中无法自定义标量值函数的问题
- linux目录下有斜杠,Windows和Linux路径中斜杠/和反斜杠\ 的区别
- jackson 读取多文件_Spring Boot系列之读取配置
- 网上书店管理系统java部分代码_网上书店管理系统 java语言
- python接口自动化关联参数_python接口自动化7-参数关联
- 美术学考计算机,艺术设计专业能跨专业考计算机研究生吗?
- 腾讯视频中如何把视频进行收藏
- 火狐浏览器摄像头权限怎么开启 火狐浏览器摄像头权限开启的方法
- Chrome 69正式版浏览器遭批 恢复完整显示域名