File tree Expand file tree Collapse file tree 4 files changed +47
-3
lines changed
best-time-to-buy-and-sell-stock-with-cooldown
form-array-by-concatenating-subarrays-of-another-array
minimum-elements-to-add-to-form-a-given-sum Expand file tree Collapse file tree 4 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/form-array-by-concatenating-subarrays-of-another-array/
49
+
50
+ https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown/
51
+
48
52
https://leetcode-cn.com/problems/minimum-elements-to-add-to-form-a-given-sum/
49
53
50
54
https://leetcode.cn/problems/checking-existence-of-edge-length-limited-paths-ii/
Original file line number Diff line number Diff line change
1
+ function maxProfit ( prices : number [ ] ) : number {
2
+ const n = prices . length ;
3
+ let r1 = - prices [ 0 ] ;
4
+ let r2 = 0 ;
5
+ let r3 = 0 ;
6
+ for ( let i = 1 ; i < n ; i ++ ) {
7
+ const newR1 = Math . max ( r1 , r3 - prices [ i ] ) ;
8
+ const newR2 = r1 + prices [ i ] ;
9
+ const newR3 = Math . max ( r3 , r2 ) ;
10
+ r1 = newR1 ;
11
+ r2 = newR2 ;
12
+ r3 = newR3 ;
13
+ }
14
+ return Math . max ( r3 , r2 ) ;
15
+ }
16
+ export default maxProfit ;
Original file line number Diff line number Diff line change
1
+ function canChoose ( groups : number [ ] [ ] , nums : number [ ] ) : boolean {
2
+ let i = 0 ;
3
+ for ( let k = 0 ; k < nums . length && i < groups . length ; ) {
4
+ if ( check ( groups [ i ] , nums , k ) ) {
5
+ k += groups [ i ] . length ;
6
+ i ++ ;
7
+ } else {
8
+ k ++ ;
9
+ }
10
+ }
11
+ return i === groups . length ;
12
+ }
13
+
14
+ function check ( g : number [ ] , nums : number [ ] , k : number ) {
15
+ if ( k + g . length > nums . length ) {
16
+ return false ;
17
+ }
18
+ for ( let j = 0 ; j < g . length ; j ++ ) {
19
+ if ( g [ j ] !== nums [ k + j ] ) {
20
+ return false ;
21
+ }
22
+ }
23
+ return true ;
24
+ }
25
+ export default canChoose ;
Original file line number Diff line number Diff line change 1
1
function minElements ( nums : number [ ] , limit : number , goal : number ) : number {
2
-
3
- return Math . ceil ( Math . abs ( goal - nums . reduce ( ( a , b ) => a + b ) ) / limit ) ;
2
+ return Math . ceil ( Math . abs ( goal - nums . reduce ( ( a , b ) => a + b ) ) / limit ) ;
4
3
}
5
- export default minElements
4
+ export default minElements ;
You can’t perform that action at this time.
0 commit comments