File tree Expand file tree Collapse file tree 3 files changed +25
-19
lines changed
global-and-local-inversions Expand file tree Collapse file tree 3 files changed +25
-19
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/global-and-local-inversions
49
+
48
50
https://leetcode.cn/problems/maximum-units-on-a-truck
49
51
50
52
https://leetcode.cn/problems/split-array-with-same-average
Original file line number Diff line number Diff line change
1
+ function isIdealPermutation ( nums : number [ ] ) : boolean {
2
+ return nums . every ( ( v , i ) => Math . abs ( v - i ) <= 1 ) ;
3
+ }
4
+ export default isIdealPermutation ;
Original file line number Diff line number Diff line change 1
- export default function maximumUnits (
2
- boxTypes : number [ ] [ ] ,
3
- truckSize : number
4
- ) : number {
5
- boxTypes . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] ) ;
6
- let res = 0 ;
7
- for ( const boxType of boxTypes ) {
8
- const numberOfBoxes = boxType [ 0 ] ;
9
- const numberOfUnitsPerBox = boxType [ 1 ] ;
10
- if ( numberOfBoxes < truckSize ) {
11
- res += numberOfBoxes * numberOfUnitsPerBox ;
12
- truckSize -= numberOfBoxes ;
13
- } else {
14
- res += truckSize * numberOfUnitsPerBox ;
15
- break ;
16
- }
17
- }
18
- return res ;
19
- }
1
+ export default function maximumUnits (
2
+ boxTypes : number [ ] [ ] ,
3
+ truckSize : number ,
4
+ ) : number {
5
+ boxTypes . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] ) ;
6
+ let res = 0 ;
7
+ for ( const boxType of boxTypes ) {
8
+ const numberOfBoxes = boxType [ 0 ] ;
9
+ const numberOfUnitsPerBox = boxType [ 1 ] ;
10
+ if ( numberOfBoxes < truckSize ) {
11
+ res += numberOfBoxes * numberOfUnitsPerBox ;
12
+ truckSize -= numberOfBoxes ;
13
+ } else {
14
+ res += truckSize * numberOfUnitsPerBox ;
15
+ break ;
16
+ }
17
+ }
18
+ return res ;
19
+ }
You can’t perform that action at this time.
0 commit comments