File tree 3 files changed +27
-3
lines changed
3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 82
82
| [ 111] [ 111-question ] | [ Minimum Depth of Binary Tree] [ 111-tips ] | [ Easy] [ E ] | [ ✅] [ 111-java ] | [ ✅] [ 111-js ] | [ ✅] [ 111-kotlin ] |
83
83
| [ 112] [ 112-question ] | [ Path Sum] [ 112-tips ] | [ Easy] [ E ] | [ ✅] [ 112-java ] | [ ✅] [ 112-js ] | [ ✅] [ 112-kotlin ] |
84
84
| [ 118] [ 118-question ] | [ Pascal's Triangle] [ 118-tips ] | [ Easy] [ E ] | [ ✅] [ 118-java ] | [ ✅] [ 118-js ] | [ ✅] [ 118-kotlin ] |
85
- | [ 119] [ 119-question ] | [ Pascal's Triangle II] [ 119-tips ] | [ Easy] [ E ] | [ ✅] [ 119-java ] | [ ✅] [ 119-js ] | [ ✅] [ 119-kotlin ] |
86
- | [ 121] [ 121-question ] | [ Best Time to Buy and Sell Stock] [ 121-tips ] | [ Easy] [ E ] | [ ✅] [ 121-java ] | [ ✅] [ 121-js ] | [ ✅] [ 121-kotlin ] |
87
- | [ 122] [ 122-question ] | [ Best Time to Buy and Sell Stock II] [ 122-tips ] | [ Easy] [ E ] | [ ✅] [ 122-java ] | | [ ✅] [ 122-kotlin ] |
85
+ | [ 119] [ 119-question ] | [ Pascal's Triangle II] [ 119-tips ] | [ Easy] [ E ] | [ ✅] [ 119-java ] | [ ✅] [ 119-js ] | [ ✅] [ 119-kotlin ] |
86
+ | [ 121] [ 121-question ] | [ Best Time to Buy and Sell Stock] [ 121-tips ] | [ Easy] [ E ] | [ ✅] [ 121-java ] | [ ✅] [ 121-js ] | [ ✅] [ 121-kotlin ] |
87
+ | [ 122] [ 122-question ] | [ Best Time to Buy and Sell Stock II] [ 122-tips ] | [ Easy] [ E ] | [ ✅] [ 122-java ] | [ ✅ ] [ 122-js ] | [ ✅] [ 122-kotlin ] |
88
88
| [ 125] [ 125-question ] | [ Valid Palindrome] [ 125-tips ] | [ Easy] [ E ] | | | [ ✅] [ 125-kotlin ] |
89
89
| [ 136] [ 136-question ] | [ Single Number] [ 136-tips ] | [ Easy] [ E ] | | | [ ✅] [ 136-kotlin ] |
90
90
| [ 141] [ 141-question ] | [ Linked List Cycle] [ 141-tips ] | [ Easy] [ E ] | [ ✅] [ 141-java ] | | - |
@@ -464,6 +464,7 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
464
464
[ 118-js ] : ./src/_118/Solution.js
465
465
[ 119-js ] : ./src/_119/Solution.js
466
466
[ 121-js ] : ./src/_121/Solution.js
467
+ [ 122-js ] : ./src/_122/Solution.js
467
468
[ 226-js ] : ./src/_226/Solution.js
468
469
[ 561-js ] : ./src/_561/Solution.js
469
470
[ 643-js ] : ./src/_643/Solution.js
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } prices
3
+ * @return {number }
4
+ */
5
+ var maxProfit = function ( prices ) {
6
+ let profit = 0 ;
7
+ for ( let i = 0 ; i < prices . length - 1 ; i ++ ) {
8
+ const possibleProfit = prices [ i + 1 ] - prices [ i ] ;
9
+ profit = Math . max ( profit + possibleProfit , profit ) ;
10
+ }
11
+ return profit ;
12
+ } ;
Original file line number Diff line number Diff line change @@ -39,6 +39,17 @@ class Solution {
39
39
}
40
40
```
41
41
42
+ JavaScript
43
+ ``` JavaScript
44
+ var maxProfit = function (prices ) {
45
+ let profit = 0 ;
46
+ for (let i = 0 ; i < prices .length - 1 ; i++ ) {
47
+ const possibleProfit = prices[i + 1 ] - prices[i];
48
+ profit = Math .max (profit + possibleProfit, profit);
49
+ }
50
+ return profit;
51
+ };
52
+ ```
42
53
## 结语
43
54
44
55
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[ LeetCode-Solution] [ ls ]
You can’t perform that action at this time.
0 commit comments