Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 |
| 30 |
Tags
- 금융문자분석경진대회
- 우분투
- Baekjoon
- hackerrank
- ChatGPT
- programmers
- leetcode
- 백준
- Git
- Kaggle
- 맥북
- SW Expert Academy
- Real or Not? NLP with Disaster Tweets
- ubuntu
- 프로그래머스
- 편스토랑 우승상품
- PYTHON
- 프로그래머스 파이썬
- 편스토랑
- 파이썬
- dacon
- 더현대서울 맛집
- gs25
- 캐치카페
- Docker
- AI 경진대회
- 코로나19
- github
- 자연어처리
- 데이콘
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 215. Kth Largest Element in an Array (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 215. Kth Largest Element in an Array (Python)
솜씨좋은장씨 2020. 10. 19. 23:42728x90
반응형

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
Example 1:
Input: [3,2,1,5,6,4] and k = 2
Output: 5
Example 2:
Input: [3,2,3,1,2,4,5,5,6] and k = 4
Output: 4
Note:
You may assume k is always valid, 1 ≤ k ≤ array's length.
Solution
class Solution:
def findKthLargest(self, nums: List[int], k: int) -> int:
sorted_list = sorted(nums, reverse=True)
return sorted_list[k-1]



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
| [leetCode] 1078. Occurrences After Bigram (Python) (0) | 2020.10.21 |
|---|---|
| [leetCode] 451. Sort Characters By Frequency (Python) (0) | 2020.10.20 |
| [leetCode] 347. Top K Frequent Elements (Python) (0) | 2020.10.14 |
| [leetCode] 442. Find All Duplicates in an Array (Python) (0) | 2020.10.13 |
| [leetCode] 504. Base 7 (Python) (0) | 2020.10.12 |
Comments