Leetcodes Solutions 9 Palindrome Number

匯總

雪之下雪乃:leetcode解題總匯?

zhuanlan.zhihu.com圖標

Determine whether an integer is a palindrome. Do this without extra space.

思路1

class Solution{public: bool isPalindrome(int x){ if(x < 0 || (x != 0 && x % 10 == 0)) return false; int sum = 0; while(x > sum){ sum = sum * 10 + x % 10; x = x / 10; } return (x == sum)||(x == sum / 10); //left operand is true when even, right operand is true when odd }};

推薦閱讀:

浙江大學-數據結構-歸併排序-9.4.2
浙江大學-數據結構-小白專場:最小路徑問題-7.1.1
手把手教你實現一個優先隊列
SkipList的原理與實現
浙江大學-數據結構-選講Huffman Codes-7.4.3

TAG:演算法 | 數據結構 | 編程 |