File tree 3 files changed +32
-1
lines changed
3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 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
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-kotlin ] |
86
+ | [ 121] [ 121-question ] | [ Best Time to Buy and Sell Stock] [ 121-tips ] | [ Easy] [ E ] | [ ✅] [ 121-java ] | [ ✅ ] [ 121-js ] | [ ✅] [ 121-kotlin ] |
87
87
| [ 122] [ 122-question ] | [ Best Time to Buy and Sell Stock II] [ 122-tips ] | [ Easy] [ E ] | [ ✅] [ 122-java ] | | [ ✅] [ 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 ] |
@@ -463,6 +463,7 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
463
463
[ 112-js ] : ./src/_112/Solution.js
464
464
[ 118-js ] : ./src/_118/Solution.js
465
465
[ 119-js ] : ./src/_119/Solution.js
466
+ [ 121-js ] : ./src/_121/Solution.js
466
467
[ 226-js ] : ./src/_226/Solution.js
467
468
[ 561-js ] : ./src/_561/Solution.js
468
469
[ 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 finalProfit = 0
7
+ for ( var i = 0 ; i < prices . length ; i ++ ) {
8
+ for ( var j = 0 ; j < i ; j ++ ) {
9
+ let profit = prices [ i ] - prices [ j ]
10
+ if ( profit > finalProfit ) {
11
+ finalProfit = profit
12
+ }
13
+ }
14
+ }
15
+ return finalProfit
16
+ } ;
Original file line number Diff line number Diff line change @@ -62,6 +62,20 @@ class Solution {
62
62
}
63
63
```
64
64
65
+ ``` JavaScript
66
+ var maxProfit = function (prices ) {
67
+ let finalProfit = 0
68
+ for (var i = 0 ; i < prices .length ; i++ ) {
69
+ for (var j = 0 ; j < i; j++ ) {
70
+ let profit = prices[i] - prices[j]
71
+ if (profit > finalProfit) {
72
+ finalProfit = profit
73
+ }
74
+ }
75
+ }
76
+ return finalProfit
77
+ };
78
+ ```
65
79
## 结语
66
80
67
81
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[ LeetCode-Solution] [ ls ]
You can’t perform that action at this time.
0 commit comments