- 博客(3)
- 收藏
- 关注
原创 打卡5(回文数)
class Solution { public: bool isPalindrome(int x) { if (x < 0 || (x % 10 == 0 && x != 0)) { return false; } int a = 0; while (x > a) { a = a * 10 + x % 10; x /= 10; } if(x==a) return true; if((a/10)==x) return true; else return false; } };
2020-06-16 23:18:54 80
原创 第四天打卡(两数之和)
class Solution { public: vector twoSum(vector& nums, int target) { for(int i = 0;i < nums.size()-1;i ++) { for(int j = i+1;j < nums.size();j++) { if(nums[i] + nums[j] == target) { return {i,j}; } } } return {}; } };
2020-06-14 16:42:14 139
原创 第三天打卡(爬楼梯)
class Solution { public: int climbStairs(int n) { int a=1,b=2,c; if(n1) c=1; if(n2) c=2; for(int i=3;i<=n;i++){ c=a+b; a=b; b=c; } return c; } };
2020-06-13 15:34:45 110
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人