728x90
nums의 숫자가 3개 이상이면, 세 번째로 큰 수를 return
2개 이하면, 가장 큰 수를 return하는 문제
class Solution:
def thirdMax(self, nums: List[int]) -> int:
n = sorted(list(set(nums)))
if len(n) < 3:
return n[-1]
else:
return n[-3]
set 후 list를 취해준 것을 sorted까지 진행했다(음수까지 정렬하려면 필요했음)
Runtime : 0ms
Memory : 19.16MB (21.26%)
728x90
'코딩 공부 > Leetcode' 카테고리의 다른 글
[Python] 1752. Check if Array Is Sorted and Rotated (0) | 2025.02.03 |
---|---|
[Python] 448. Find All Numbers Disappeared in an Array (0) | 2025.02.02 |
[Python] 1051. Height Checker (0) | 2025.01.31 |
[Python] 905. Sort Array By Parity (0) | 2025.01.30 |
[Python] 283. Move Zeroes (0) | 2025.01.29 |