거누의 개발노트
[파이썬] 215. Kth Largest Element in an Array - 리트코드 본문
반응형
문제
정수 배열 nums이 주어지면 배열에서 k번째로 가장 큰 요소를 반환 하는 프로그램을 작성하시오.
입력
Input: nums = [3,2,1,5,6,4], k = 2
출력
Output: 5
작성한 코드1
class Solution:
def findKthLargest(self, nums: List[int], k: int) -> int:
return heapq.nlargest(k,nums)[-1]
https://leetcode.com/problems/kth-largest-element-in-an-array/
반응형
'코딩테스트' 카테고리의 다른 글
[파이썬] 75. Sort Colors - 리트코드 (0) | 2022.05.27 |
---|---|
[파이썬] 백준 - 최소 힙 - 1927 (0) | 2022.05.25 |
[파이썬] 1337. The K Weakest Rows in a Matrix - 리트코드 (0) | 2022.05.25 |
[파이썬] 1464. Maximum Product of Two Elements in an Array - 리트코드 (0) | 2022.05.25 |
[파이썬] 297. Serialize and Deserialize Binary Tree - 리트코드 (0) | 2022.05.24 |
Comments