diff --git a/bangdori/Third Maximum Number.js b/bangdori/Third Maximum Number.js new file mode 100644 index 0000000..6510f17 --- /dev/null +++ b/bangdori/Third Maximum Number.js @@ -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]; +};