[LeetCode] 564. Find the Closest Palindrome 深入浅出讲解和代码示例
来源:互联网 发布:淘宝刷两单会坐牢吗 编辑:程序博客网 时间:2024/05/29 19:02
1、汇总概要
xx
2、题目
Given an integer n, find the closest integer (not including itself), which is a palindrome.
The 'closest' is defined as absolute difference minimized between two integers.
Example 1:
Input: "123"Output: "121"
Note:
- The input n is a positive integer represented by string, whose length will not exceed 18.
- If there is a tie, return the smaller one as answer.
3、审题
给定一个整数,求出它最近的回文串
4、解题思路
该题较简单,直接上代码。
5、代码示例 - Python
class Solution(object): def nearestPalindromic(self, n): for i in range(n,1,-1): istr = str(i) leng = len(istr) flag = 1 for j in range(0,leng/2): if istr[j] != istr[leng-1-j]: flag = 0 if flag == 1: #is the palindromic return iif __name__ == "__main__": st = Solution() res = st.nearestPalindromic(15500987) print "\nres-------: ",res
---------------------------------------------------------------------------------------------------
本文链接:http://blog.csdn.net/karen0310/article/details/xx
请尊重作者的劳动成果,转载请注明出处!
---------------------------------------------------------------------------------------------------
阅读全文
1 0
- [LeetCode] 564. Find the Closest Palindrome 深入浅出讲解和代码示例
- leetcode 564. Find the Closest Palindrome
- 564. Find the Closest Palindrome
- 564. Find the Closest Palindrome
- leetcode 564. Find the Closest Palindrome(java)
- [Leetcode] 564. Find the Closest Palindrome 解题报告
- 564. Find the Closest Palindrome (Hard)
- LeetCode 564: Find the Closest Palindrome(python)
- [LeetCode]632. Smallest Range 深入浅出讲解和代码示例
- [LeetCode]127. Word Ladder 深入浅出讲解和代码示例
- [LeetCode]147. Insertion Sort List 深入浅出讲解和代码示例
- [LeetCode]146. LRU Cache 深入浅出讲解和代码示例
- [LeetCode]44. Wildcard Matching 深入浅出讲解和代码示例
- [LeetCode]68. Text Justification 深入浅出讲解和代码示例
- [LeetCode]493. Reverse Pairs 深入浅出算法讲解和代码示例
- leetcode 564. Find the Closest Palindrome 距离自己最近的回文数字
- [LeetCode]149. Max Points on a Line 深入浅出讲解和代码示例
- [LeetCode]420. Strong Password Checker深入浅出算法讲解和代码示例
- JEESZ RestFul服务介绍
- sass常用函数总结
- Bitmap与Uri互转、Activity传递Bitmap、分享Bitmap
- ECB模式详解
- 浏览器插件开发-纯属兴趣
- [LeetCode] 564. Find the Closest Palindrome 深入浅出讲解和代码示例
- leetcode题解-86. Partition List
- Java对象、对象引用关系及参数传递讨论
- Free, simple code to find out what SQL statements are running slow in SQL Server right now
- python学习中的reduce()函数和lambda表达式
- Android Hal层简要分析
- HTML标签
- Spring-@Autowired注解、@Resource注解和@Service注解
- Java消息中间件--JMS规范