mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
@ -76,7 +76,7 @@ public:
|
||||
```
|
||||
|
||||
时间复杂度:O(n)
|
||||
时间复杂度:O(1)
|
||||
空间复杂度:O(1)
|
||||
|
||||
效率如下:
|
||||
|
||||
|
@ -88,7 +88,8 @@
|
||||
|
||||
|
||||
以上分析完毕,C++代码如下:
|
||||
```
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
int climbStairs(int n) {
|
||||
|
@ -202,6 +202,7 @@ public:
|
||||
for (int i = 0; i < nums.size(); i++) sum += nums[i];
|
||||
if (S > sum) return 0; // 此时没有方案
|
||||
if ((S + sum) % 2 == 1) return 0; // 此时没有方案
|
||||
if (S + sum < 0) return 0; // 以确保bagSize为正数
|
||||
int bagSize = (S + sum) / 2;
|
||||
vector<int> dp(bagSize + 1, 0);
|
||||
dp[0] = 1;
|
||||
|
Reference in New Issue
Block a user