File tree 6 files changed +87
-4
lines changed
2154.Keep Multiplying Found Values by Two
2155.All Divisions With the Highest Score of a Binary Array
6 files changed +87
-4
lines changed Original file line number Diff line number Diff line change 75
75
### ** TypeScript**
76
76
77
77
``` ts
78
-
78
+ function findFinalValue(nums : number [], original : number ): number {
79
+ let set: Set <number > = new Set (nums );
80
+ while (set .has (original )) {
81
+ original *= 2 ;
82
+ }
83
+ return original ;
84
+ };
79
85
```
80
86
81
87
### ** ...**
Original file line number Diff line number Diff line change 65
65
### ** TypeScript**
66
66
67
67
``` ts
68
-
68
+ function findFinalValue(nums : number [], original : number ): number {
69
+ let set: Set <number > = new Set (nums );
70
+ while (set .has (original )) {
71
+ original *= 2 ;
72
+ }
73
+ return original ;
74
+ };
69
75
```
70
76
71
77
### ** ...**
Original file line number Diff line number Diff line change
1
+ function findFinalValue ( nums : number [ ] , original : number ) : number {
2
+ let set : Set < number > = new Set ( nums ) ;
3
+ while ( set . has ( original ) ) {
4
+ original *= 2 ;
5
+ }
6
+ return original ;
7
+ } ;
Original file line number Diff line number Diff line change 91
91
### ** TypeScript**
92
92
93
93
``` ts
94
-
94
+ function maxScoreIndices(nums : number []): number [] {
95
+ const n = nums .length ;
96
+ const total = nums .reduce ((a , c ) => a + c , 0 );
97
+ let left = 0 , right = total ;
98
+ let record: Array <number > = [total ];
99
+ for (const num of nums ) {
100
+ if (num == 0 ) {
101
+ left ++ ;
102
+ } else {
103
+ right -- ;
104
+ }
105
+ record .push (left + right );
106
+ }
107
+ const max = Math .max (... record );
108
+ let ans: Array <number > = [];
109
+ for (let i = 0 ; i <= n ; i ++ ) {
110
+ if (record [i ] == max ) {
111
+ ans .push (i );
112
+ }
113
+ }
114
+ return ans ;
115
+ };
95
116
```
96
117
97
118
### ** ...**
Original file line number Diff line number Diff line change @@ -84,7 +84,28 @@ Only index 0 has the highest possible division score 2.
84
84
### ** TypeScript**
85
85
86
86
``` ts
87
-
87
+ function maxScoreIndices(nums : number []): number [] {
88
+ const n = nums .length ;
89
+ const total = nums .reduce ((a , c ) => a + c , 0 );
90
+ let left = 0 , right = total ;
91
+ let record: Array <number > = [total ];
92
+ for (const num of nums ) {
93
+ if (num == 0 ) {
94
+ left ++ ;
95
+ } else {
96
+ right -- ;
97
+ }
98
+ record .push (left + right );
99
+ }
100
+ const max = Math .max (... record );
101
+ let ans: Array <number > = [];
102
+ for (let i = 0 ; i <= n ; i ++ ) {
103
+ if (record [i ] == max ) {
104
+ ans .push (i );
105
+ }
106
+ }
107
+ return ans ;
108
+ };
88
109
```
89
110
90
111
### ** ...**
Original file line number Diff line number Diff line change
1
+ function maxScoreIndices ( nums : number [ ] ) : number [ ] {
2
+ const n = nums . length ;
3
+ const total = nums . reduce ( ( a , c ) => a + c , 0 ) ;
4
+ let left = 0 , right = total ;
5
+ let record : Array < number > = [ total ] ;
6
+ for ( const num of nums ) {
7
+ if ( num == 0 ) {
8
+ left ++ ;
9
+ } else {
10
+ right -- ;
11
+ }
12
+ record . push ( left + right ) ;
13
+ }
14
+ const max = Math . max ( ...record ) ;
15
+ let ans : Array < number > = [ ] ;
16
+ for ( let i = 0 ; i <= n ; i ++ ) {
17
+ if ( record [ i ] == max ) {
18
+ ans . push ( i ) ;
19
+ }
20
+ }
21
+ return ans ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments