Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- KPT회고
- Python
- JavaScript
- 코딩테스트 준비
- DesignPattern
- 빈 조회 2개 이상
- 구글 OAuth login
- 프로그래머스
- 개발자 취업
- jwt
- @FeignClient
- 프로그래머스 이중우선순위큐
- 1주일회고
- 디자인패턴
- 디자인 패턴
- spring batch 5.0
- 항해99
- 인프콘 2024
- 커스텀 헤더
- jwttoken
- 단기개발자코스
- 개발자부트캠프추천
- 빈 충돌
- Spring multimodule
- 전략패턴 #StrategyPattern #디자인패턴
- TiL
- 파이썬
- 99클럽
- 취업리부트코스
- infcon 2024
Archives
- Today
- Total
m1ndy5's coding blog
LeetCode 215. Kth Largest Element in an Array with Python 본문
알고리즘 with python/알고리즘 스터디
LeetCode 215. Kth Largest Element in an Array with Python
정민됴 2024. 1. 5. 10:46https://leetcode.com/problems/kth-largest-element-in-an-array/
import heapq
class Solution:
def findKthLargest(self, nums: List[int], k: int) -> int:
nums = [-1 * num for num in nums]
heapq.heapify(nums)
answer = 0
for _ in range(k):
answer = heapq.heappop(nums)
return answer * -1
최대힙처럼 작동해야했기 때문에 -1을 곱했다.
sort로 풀어도 문제없는 문제였다.
'알고리즘 with python > 알고리즘 스터디' 카테고리의 다른 글
LeetCode 21. Merge Two Sorted Lists with Python (0) | 2024.01.06 |
---|---|
LeetCode 206.Reverse Linked List with Python (0) | 2024.01.06 |
LeetCode 1337. The K Weakest Rows in a Matrix with Python (1) | 2024.01.05 |
LeetCode 1464. Maximum Product of Two Elements in an Array with Python (0) | 2024.01.05 |
LeetCode 347. Top K Frequent Elements with Python (0) | 2024.01.04 |