File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 134
134
151|[ Reverse Words in a String] ( ./0151-reverse-words-in-a-string.js ) |Medium|
135
135
152|[ Maximum Product Subarray] ( ./0152-maximum-product-subarray.js ) |Medium|
136
136
160|[ Intersection of Two Linked Lists] ( ./0160-intersection-of-two-linked-lists.js ) |Medium|
137
+ 164|[ Maximum Gap] ( ./0164-maximum-gap.js ) |Medium|
137
138
167|[ Two Sum II - Input Array Is Sorted] ( ./0167-two-sum-ii-input-array-is-sorted.js ) |Easy|
138
139
168|[ Excel Sheet Column Title] ( ./0168-excel-sheet-column-title.js ) |Easy|
139
140
169|[ Majority Element] ( ./0169-majority-element.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 164. Maximum Gap
3
+ * https://leetcode.com/problems/maximum-gap/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an integer array nums, return the maximum difference between two successive elements in
7
+ * its sorted form. If the array contains less than two elements, return 0.
8
+ */
9
+
10
+ /**
11
+ * @param {number[] } nums
12
+ * @return {number }
13
+ */
14
+ var maximumGap = function ( nums ) {
15
+ nums . sort ( ( a , b ) => a - b ) ;
16
+ let result = 0 ;
17
+ for ( let i = 1 ; i < nums . length ; i ++ ) {
18
+ result = Math . max ( result , nums [ i ] - nums [ i - 1 ] ) ;
19
+ }
20
+ return result ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments