Skip to content

Commit 342e02d

Browse files
author
Tushar Borole
committed
414. Third Maximum Number
1 parent 24ed528 commit 342e02d

File tree

3 files changed

+90
-63
lines changed

3 files changed

+90
-63
lines changed

.idea/workspace.xml

Lines changed: 74 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
| 783 | [Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes/) | [minimum_distance_between_bst_nodes.js](minimum_distance_between_bst_nodes.js) | 88 ms | 34.7 MB | Easy |
5353
| 1013 | [Partition Array Into Three Parts With Equal Sum](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum/) | [partition_array_into_three_parts.js](partition_array_into_three_parts.js) | 72 ms | 39.6 MB | Easy |
5454
| 912 | [Sort an Array](https://leetcode.com/problems/sort-an-array/) | [Solution](sort_an_array.js) | 7176 ms | 38.9 MB | Medium |
55+
| 414 | [Third Maximum Number](https://leetcode.com/problems/third-maximum-number/) | [third_maximum_number.js](third_maximum_number.js) | 76 ms | 38 MB | Easy |
5556
| 701 | [Insert into a Binary Search Tree](https://leetcode.com/problems/insert-into-a-binary-search-tree/) | [Solution](insert_into_a_binary_search_tree.js) | 112 ms | 41.9 MB | Medium |
5657
| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Solution](binary_tree_inorder_traversal.js) | 56 ms | 33.7 MB | Medium |
5758
| 1015 | [Smallest Integer Divisible by K](https://leetcode.com/problems/smallest-integer-divisible-by-k/) | [Solution](smallest_integer_divisible.js) | 52 ms | 34.3 MB | Medium |

third_maximum_number.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var thirdMax = function(nums) {
6+
nums.sort((a, b) => b - a);
7+
nums = [...new Set(nums)];
8+
9+
if (nums.length < 3) {
10+
return nums[0];
11+
}
12+
return nums[2];
13+
};
14+
15+
thirdMax([1, 2, 3]); //?

0 commit comments

Comments
 (0)