Leetcode
我什么都布吉岛
Keep writing,Keep thinking!
展开
-
Leetcode(一)回文数
方法一:观察法 bool isPalindrome(int x) { int cur = 0; int num = x; if (x < 0) return false; while (num != 0) { cur = cur * 10 + num % 10; num = num / 10; } return cur==x; } 方法二:转成字符串 bool isPalindrome(int.原创 2022-01-18 23:03:15 · 4479 阅读 · 0 评论 -
Leetcode (二) 加一
刚开始还想把数组转成对应整数后加一,在取出每一位再转置,结果溢出了。而且题目看,这个数居然有100位,显然转成数字不太现实。下面是一种解题思路: 写成代码如下: vector<int> plusOne(vector<int>& digits) { vector<int> res = digits; size_t cur = res.size() - 1; while (1) { if (res[cur.原创 2022-01-19 21:33:44 · 107 阅读 · 0 评论
分享