Skip to content

Commit

Permalink
[Leetcode - Easy] Third Maximum Number (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Dec 5, 2024
2 parents 15915e7 + c5ac0bf commit f17a05a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bangdori/Third Maximum Number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @param {number[]} nums
* @return {number}
*/
var thirdMax = function (nums) {
const sortedNums = nums.sort((a, b) => b - a);
const uniqueNums = [...new Set(sortedNums)];

if (uniqueNums.length <= 2) {
return uniqueNums[0];
}

return uniqueNums[2];
};

0 comments on commit f17a05a

Please sign in to comment.