判断一个数是否为回文数字,如1,2,3,121,1001,999都是回文数字,10,9898就不是回文数字。 解法:判断对称中心两端数字是否相同。 代码如下: bool isPalindrome(int x) { if (x<0 || (x != 0 && x % 10 == 0)) return ...
分类:
其他好文 时间:
2017-06-10 12:15:30
阅读次数:
153
I: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For exa ...
分类:
其他好文 时间:
2017-06-09 19:24:32
阅读次数:
249
本来推断回文串是一件非常easy的事情,仅仅须要反转字符串后在与原字符串相比較就可以。这道题目明白说明不能使用额外的空间。那么使用将其分解连接成字符串的方法便不是可行的。仅仅好採用数学的方式: 每次取最高位和最低位相比較,总的位数能够用一个while先处理出来,循环直至取余和除数相等。 详细见代码: ...
分类:
其他好文 时间:
2017-06-09 14:10:57
阅读次数:
133
Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 这个follow up要求O(n)的时间和O(1)的空间,可以先re ...
分类:
其他好文 时间:
2017-06-07 23:21:04
阅读次数:
274
https://leetcode.com/problems/valid-palindrome/#/description Given a string, determine if it is a palindrome, considering only alphanumeric characters ...
分类:
其他好文 时间:
2017-06-05 22:09:10
阅读次数:
170
problem: Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be pal ...
分类:
其他好文 时间:
2017-06-04 22:40:30
阅读次数:
223
题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are ...
分类:
编程语言 时间:
2017-06-04 15:38:18
阅读次数:
252
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thi ...
分类:
其他好文 时间:
2017-06-04 10:51:59
阅读次数:
138
Cheapest Palindrome Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6861 Accepted: 3327 Description Keeping track of all the cows can be a ...
分类:
其他好文 时间:
2017-06-03 19:24:52
阅读次数:
232
看到Palindrome的题目。首先想到的应该是中心问题,然后从中心出发,思考怎样解决。 DP问题通常是从更加小的问题转化到更加大的问题。然后是从地往上 bottom up地计算答案的。 能得出状态转移方程就好办了,本题的状态转移方程是: if (cowID[i] == cow{j]) tbl[id ...
分类:
其他好文 时间:
2017-05-30 22:01:28
阅读次数:
152