LeetCode-数学-9. 回文数
生活随笔
收集整理的這篇文章主要介紹了
LeetCode-数学-9. 回文数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
9. 回文數
思路一:先使用vector容器存下每一位的數據,在判斷容器里面首尾是否相等
class Solution { public:bool isPalindrome(int x) {if(x<0) return false;vector<int> data;while(x!=0){int temp = x%10;x = x/10;data.push_back(temp);}int start = 0,end=data.size()-1;while(start<end){if(data[start]!=data[end]){return false;}start++;end--;}return true;} };總結
以上是生活随笔為你收集整理的LeetCode-数学-9. 回文数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode-二分查找-35. 搜索
- 下一篇: LeetCode-位运算-36. 只出现