leetcode---container-with-most-water---数组
2018-01-07 16:51
399 查看
Determine whether an integer is a palindrome. Do this without extra space.
click to show spoilers.
Some hints:
Could negative integers be palindromes? (ie, -1)
If you are thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you have solved the problem “Reverse Integer”, you know that the reversed integer might overflow. How would you handle such case?
There is a more generic way of solving this problem.
click to show spoilers.
Some hints:
Could negative integers be palindromes? (ie, -1)
If you are thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you have solved the problem “Reverse Integer”, you know that the reversed integer might overflow. How would you handle such case?
There is a more generic way of solving this problem.
class Solution { public: int reverse(int x) { int n = 0; while(x) { n = n * 10 + x % 10; x /= 10; } return n; } bool isPalindrome(int x) { if(x < 0) return false; return x == reverse(x); } };
相关文章推荐
- Leetcode - Container With Most Water
- LeetCode 011: Container With Most Water
- [Leetcode]Container With Most Water
- [LeetCode]-011-Container With Most Water
- [LeetCode]-011-Container_With_Most_Water
- leetcode - Container With Most Water
- leetcode解题方案--011--Container With Most Water
- [LeetCode]Container With Most Water、Trapping Rain Water
- 【leetcode刷提笔记】Container With Most Water
- [LeetCode] Container With Most Water
- LeetCode | Container with most water(装最多的水)
- LeetCode -- Container With Most Water
- leetcode11 Container With Most Water
- [Leetcode] Container With Most Water
- leetcode 11 - Container With Most Water
- leetcode——Container With Most Water
- 11 leetcode - Container with most water
- 【Leetcode】Container With Most Water
- leetcode_Container With Most Water
- *LeetCode-Container With Most Water