Skip to content

Commit

Permalink
Third Maximum Number 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
BangDori committed Nov 27, 2024
1 parent 15915e7 commit c5ac0bf
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 c5ac0bf

Please sign in to comment.