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 121
121
374|[ Guess Number Higher or Lower] ( ./0374-guess-number-higher-or-lower.js ) |Medium|
122
122
383|[ Ransom Note] ( ./0383-ransom-note.js ) |Easy|
123
123
387|[ First Unique Character in a String] ( ./0387-first-unique-character-in-a-string.js ) |Easy|
124
+ 414|[ Third Maximum Number] ( ./0414-third-maximum-number.js ) |Easy|
124
125
442|[ Find All Duplicates in an Array] ( ./0442-find-all-duplicates-in-an-array.js ) |Medium|
125
126
448|[ Find All Numbers Disappeared in an Array] ( ./0448-find-all-numbers-disappeared-in-an-array.js ) |Easy|
126
127
451|[ Sort Characters By Frequency] ( ./0451-sort-characters-by-frequency.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 414. Third Maximum Number
3
+ * https://leetcode.com/problems/third-maximum-number/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an integer array nums, return the third distinct maximum number in this array.
7
+ * If the third maximum does not exist, return the maximum number.
8
+ */
9
+
10
+ /**
11
+ * @param {number[] } nums
12
+ * @return {number }
13
+ */
14
+ var thirdMax = function ( nums ) {
15
+ const sortedSet = [ ...new Set ( nums ) ] . sort ( ( a , b ) => a - b ) ;
16
+ const thirdMax = sortedSet [ sortedSet . length - 3 ] ;
17
+
18
+ return thirdMax !== undefined
19
+ ? thirdMax
20
+ : sortedSet [ sortedSet . length - 1 ] ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments