Skip to content

Commit a8863f7

Browse files
Add C++ implementation
Signed-off-by: begeekmyfriend <begeekmyfriend@gmail.com>
1 parent 9663998 commit a8863f7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

072_edit_distance/edit_distance.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Solution {
2323
}
2424
}
2525
}
26-
26+
2727
return dp[word1.length()][word2.length()];
2828
}
2929
};

1373_maximum_sum_bst_in_binary_tree/max_bst.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Solution {
4141
int sum = root->val + subl->sum_val + subr->sum_val;
4242
if (subl->isBst && subr->isBst && root->val > subl->max_val && root->val < subr->min_val) {
4343
max_sum = max(sum, max_sum);
44+
// For leaf nodes
4445
int min_val = min(root->val, subl->min_val);
4546
int max_val = max(root->val, subr->max_val);
4647
return new TreeInfo(true, min_val, max_val, sum);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
class Solution {
6+
public:
7+
bool canPartition(vector<int>& nums) {
8+
int sum = 0;
9+
for (int n : nums) {
10+
sum += n;
11+
}
12+
if (sum % 2 != 0) {
13+
return false;
14+
}
15+
16+
vector<bool> dp(sum / 2 + 1, false);
17+
dp[0] = true;
18+
for (int i = 0; i < nums.size(); i++) {
19+
for (int j = sum / 2 ; j >= 0; j--) {
20+
if (j >= nums[i]) {
21+
dp[j] = dp[j] || dp[j - nums[i]];
22+
}
23+
}
24+
}
25+
26+
return dp[sum / 2];
27+
}
28+
};

0 commit comments

Comments
 (0)