Skip to content

Commit 233f351

Browse files
committed
leetcode
1 parent 99add69 commit 233f351

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎LeetCode/maxProfitII.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
int maxProfit(vector<int> &prices) {
4+
int ret = 0;
5+
for (int i = 1; i < prices.size(); ++i) {
6+
ret += max(0, prices[i] - prices[i - 1]);
7+
}
8+
return ret;
9+
}
10+
};

‎LeetCode/minDepth.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
struct TreeNode {
5+
int val;
6+
TreeNode *left;
7+
TreeNode *right;
8+
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
9+
};
10+
11+
class Solution {
12+
public:
13+
int minDepth(TreeNode *root) {
14+
if (root == NULL) return 0;
15+
if (root->left == NULL && root->right == NULL) return 1;
16+
if (root->left == NULL) return 1 + minDepth(root->right);
17+
if (root->right == NULL) return 1 + minDepth(root->left);
18+
return min(1 + minDepth(root->left), 1 + minDepth(root->right));
19+
}
20+
};
21+
22+
int main() {
23+
return 0;
24+
}

0 commit comments

Comments
 (0)