File tree Expand file tree Collapse file tree 2 files changed +24
-25
lines changed
set-intersection-size-at-least-two
yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof Expand file tree Collapse file tree 2 files changed +24
-25
lines changed Original file line number Diff line number Diff line change 1
- function intersectionSizeTwo ( intervals : number [ ] [ ] ) : number {
2
- intervals . sort ( ( a , b ) => {
3
- return a [ 1 ] < b [ 1 ] || ( a [ 1 ] === b [ 1 ] && a [ 0 ] > b [ 0 ] ) ? - 1 : 1 ;
4
- } ) ;
5
-
6
- let last1 = - 1 ;
7
- let last2 = - 1 ;
8
- let res = 0 ;
9
- for ( const q of intervals ) {
10
- if ( q [ 0 ] > last2 ) {
11
- last1 = q [ 1 ] - 1 ;
12
- last2 = q [ 1 ] ;
13
- res += 2 ;
14
- } else if ( q [ 0 ] > last1 ) {
15
- last1 = last2 ;
16
- last2 = q [ 1 ] ;
17
- res ++ ;
18
- }
19
- }
20
- return res ;
21
- }
22
- export default intersectionSizeTwo ;
1
+ function intersectionSizeTwo ( intervals : number [ ] [ ] ) : number {
2
+ intervals . sort ( ( a , b ) => {
3
+ return a [ 1 ] < b [ 1 ] || ( a [ 1 ] === b [ 1 ] && a [ 0 ] > b [ 0 ] ) ? - 1 : 1 ;
4
+ } ) ;
5
+
6
+ let last1 = - 1 ;
7
+ let last2 = - 1 ;
8
+ let res = 0 ;
9
+ for ( const q of intervals ) {
10
+ if ( q [ 0 ] > last2 ) {
11
+ last1 = q [ 1 ] - 1 ;
12
+ last2 = q [ 1 ] ;
13
+ res += 2 ;
14
+ } else if ( q [ 0 ] > last1 ) {
15
+ last1 = last2 ;
16
+ last2 = q [ 1 ] ;
17
+ res ++ ;
18
+ }
19
+ }
20
+ return res ;
21
+ }
22
+ export default intersectionSizeTwo ;
Original file line number Diff line number Diff line change 1
- export default
2
- function lastRemaining ( n : number , m : number ) : number {
3
- let f = 0 ;
1
+ export default function lastRemaining ( n : number , m : number ) : number {
2
+ let f = 0 ;
4
3
for ( let i = 2 ; i <= n ; i ++ ) {
5
4
f = ( f + m ) % i ;
6
5
}
You can’t perform that action at this time.
0 commit comments