File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 586
586
769|[ Max Chunks To Make Sorted] ( ./0769-max-chunks-to-make-sorted.js ) |Medium|
587
587
770|[ Basic Calculator IV] ( ./0770-basic-calculator-iv.js ) |Hard|
588
588
773|[ Sliding Puzzle] ( ./0773-sliding-puzzle.js ) |Hard|
589
+ 775|[ Global and Local Inversions] ( ./0775-global-and-local-inversions.js ) |Medium|
589
590
783|[ Minimum Distance Between BST Nodes] ( ./0783-minimum-distance-between-bst-nodes.js ) |Easy|
590
591
784|[ Letter Case Permutation] ( ./0784-letter-case-permutation.js ) |Medium|
591
592
790|[ Domino and Tromino Tiling] ( ./0790-domino-and-tromino-tiling.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 775. Global and Local Inversions
3
+ * https://leetcode.com/problems/global-and-local-inversions/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer array nums of length n which represents a permutation of all the
7
+ * integers in the range [0, n - 1].
8
+ *
9
+ * The number of global inversions is the number of the different pairs (i, j) where:
10
+ * - 0 <= i < j < n
11
+ * - nums[i] > nums[j]
12
+ *
13
+ * The number of local inversions is the number of indices i where:
14
+ * - 0 <= i < n - 1
15
+ * - nums[i] > nums[i + 1]
16
+ *
17
+ * Return true if the number of global inversions is equal to the number of local inversions.
18
+ */
19
+
20
+ /**
21
+ * @param {number[] } nums
22
+ * @return {boolean }
23
+ */
24
+ var isIdealPermutation = function ( nums ) {
25
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
26
+ if ( Math . abs ( nums [ i ] - i ) > 1 ) {
27
+ return false ;
28
+ }
29
+ }
30
+ return true ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments