摘要: 知识点如下: 质因数分解定理。 算术基本定理,又称为正整数的唯一分解定理,即:每个大于1的自然数均可写为质数的积,而且这些素因子按大小排列之后,写法仅有一种方式。 因此,1不是质数。 给定一个正整数n,求n的所有约数的和。 首先进行质因数分解。 将正整数 n 进行质因数分解,一般都可以写成以下形式。 阅读全文
posted @ 2018-05-21 22:55 苛性氢 阅读(283) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int rob(vector<int>& nums) { int last,next2Last,ans; if(nums.empty()){ return 0; } if(nums.size()==1){ return nums[0]; } next 阅读全文
posted @ 2018-05-21 20:55 苛性氢 阅读(340) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int maxSubArray(vector<int>& nums) { int pre=nums[0]; //int now; int maxSum=nums[0]; for(int i=1;i<nums.size();i++){ if(pre>0 阅读全文
posted @ 2018-05-21 20:48 苛性氢 阅读(74) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int maxProfit(vector<int>& prices) { if(prices.empty()){ return 0; } int minpri=prices[0]; int prof=0; for(int i=0;i<prices.s 阅读全文
posted @ 2018-05-21 20:42 苛性氢 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 最后一步走1、2个台阶。 dp[i+1]=dp[i]+dp[i-1] class Solution { public: int climbStairs(int n) { int *dp=new int[n+1]; dp[1]=1; dp[2]=2; for(int i=3;i<=n;i++){ dp 阅读全文
posted @ 2018-05-21 20:40 苛性氢 阅读(149) 评论(0) 推荐(0) 编辑