File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
minimum-swaps-to-make-sequences-increasing Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
10
10
11
11
##### 包含的内容如下
12
12
13
+ https://leetcode.cn/problems/minimum-swaps-to-make-sequences-increasing/
14
+
13
15
https://leetcode.cn/problems/6eUYwP/
14
16
15
17
https://leetcode.cn/problems/three-in-one-lcci/
Original file line number Diff line number Diff line change
1
+ export default function minSwap ( nums1 : number [ ] , nums2 : number [ ] ) : number {
2
+ const n = nums1 . length ;
3
+ let a = 0 ,
4
+ b = 1 ;
5
+ for ( let i = 1 ; i < n ; i ++ ) {
6
+ const at = a ,
7
+ bt = b ;
8
+ a = b = n ;
9
+ if ( nums1 [ i ] > nums1 [ i - 1 ] && nums2 [ i ] > nums2 [ i - 1 ] ) {
10
+ a = Math . min ( a , at ) ;
11
+ b = Math . min ( b , bt + 1 ) ;
12
+ }
13
+ if ( nums1 [ i ] > nums2 [ i - 1 ] && nums2 [ i ] > nums1 [ i - 1 ] ) {
14
+ a = Math . min ( a , bt ) ;
15
+ b = Math . min ( b , at + 1 ) ;
16
+ }
17
+ }
18
+ return Math . min ( a , b ) ;
19
+ }
You can’t perform that action at this time.
0 commit comments