[leetcode] Palindrome Number(不使用额外空间)
LeetCode number 空间 Palindrome 额外 使用
2023-09-14 09:06:22 时间
本来推断回文串是一件非常easy的事情,仅仅须要反转字符串后在与原字符串相比較就可以。这道题目明白说明不能使用额外的空间。那么使用将其分解连接成字符串的方法便不是可行的。仅仅好採用数学的方式: 每次取最高位和最低位相比較,总的位数能够用一个while先处理出来,循环直至取余和除数相等。
详细见代码:
class Solution { public: bool isPalindrome(int x) { if(x<0) //special due return false; if(x<10) return true; int curMod=0; int test=x; while(test) { curMod++; test/=10; } curMod--;// bit num int left=pow(10,curMod*1.0),right=10; while(right<=left) { if(x%right!=x/left) return false; x=x%left,x/=10; left/=100; } return true; } };
相关文章
- ☆打卡算法☆LeetCode 204. 计数质数 算法解析
- 拒绝无脑刷LeetCode,你需要知道这些套路
- LeetCode刷题系列(1)
- LeetCode周赛283,第一名送iWatch,少年你参赛了吗?
- LeetCode 刷题笔记——day 8
- LeetCode 387. 字符串中的第一个唯一字符
- 包子培训 leetcode solution 2320 Count Number of Ways to Place Houses
- 用javascript分类刷leetcode---动态规划
- 前端工程师leetcode算法面试--二分搜索算法(上)
- 初学LeetCode算法题电话号码的字母组合(虽然不难但是做出来还是很爽的)
- MySQL Error number: MY-010815; Symbol: ER_BINLOG_FILE_EXTENSION_NUMBER_RUNNING_LOW; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-14293: Number of partitioning columns does not match number of subpartitioning columns ORACLE 报错 故障修复 远程处理
- ORA-14294: Number of partitions does not match number of subpartitions ORACLE 报错 故障修复 远程处理