File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 706
706
893|[ Groups of Special-Equivalent Strings] ( ./0893-groups-of-special-equivalent-strings.js ) |Medium|
707
707
894|[ All Possible Full Binary Trees] ( ./0894-all-possible-full-binary-trees.js ) |Medium|
708
708
895|[ Maximum Frequency Stack] ( ./0895-maximum-frequency-stack.js ) |Hard|
709
+ 896|[ Monotonic Array] ( ./0896-monotonic-array.js ) |Easy|
709
710
901|[ Online Stock Span] ( ./0901-online-stock-span.js ) |Medium|
710
711
905|[ Sort Array By Parity] ( ./0905-sort-array-by-parity.js ) |Easy|
711
712
909|[ Snakes and Ladders] ( ./0909-snakes-and-ladders.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 896. Monotonic Array
3
+ * https://leetcode.com/problems/monotonic-array/
4
+ * Difficulty: Easy
5
+ *
6
+ * An array is monotonic if it is either monotone increasing or monotone decreasing.
7
+ *
8
+ * An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums
9
+ * is monotone decreasing if for all i <= j, nums[i] >= nums[j].
10
+ *
11
+ * Given an integer array nums, return true if the given array is monotonic, or false otherwise.
12
+ */
13
+
14
+ /**
15
+ * @param {number[] } nums
16
+ * @return {boolean }
17
+ */
18
+ var isMonotonic = function ( nums ) {
19
+ const isIncreasing = nums . every ( ( num , i ) => i === 0 || num >= nums [ i - 1 ] ) ;
20
+ const isDecreasing = nums . every ( ( num , i ) => i === 0 || num <= nums [ i - 1 ] ) ;
21
+ return isIncreasing || isDecreasing ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments