You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| 1430 |[Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree](/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree)| - | - |
Say you have an array for which the `i`th element is the price of a given stock on day `i`.
12
+
13
+
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).
14
+
15
+
Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).
16
+
17
+
Example 1:
18
+
19
+
```text
20
+
Input: [7,1,5,3,6,4]
21
+
Output: 7
22
+
Explanation:
23
+
Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
24
+
Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
25
+
```
26
+
27
+
Example 2:
28
+
29
+
```text
30
+
Input: [1,2,3,4,5]
31
+
Output: 4
32
+
Explanation:
33
+
Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
34
+
Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.
35
+
```
36
+
37
+
Example 3:
38
+
39
+
```text
40
+
Input: [7,6,4,3,1]
41
+
Output: 0
42
+
Explanation: In this case, no transaction is done, i.e. max profit = 0.
Given a non-empty binary tree, find the maximum path sum.
12
+
13
+
For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root.
0 commit comments