๋ณธ ๊ธ์ LeetCode Top Interview 150์ ์ ๋ฆฌ๋ ๋ฌธ์ ๋ฅผ ์์ฝํ๊ณ ์ด์ ๋ํ ๊ฐ์ธ์ ์ธ ํ์ด๋ฅผ ํฌํจํ๊ณ ์์ต๋๋ค.
๋ณธ ํฌ์คํ ์๋ฆฌ์ฆ๋ 150 list์ ์์๋ฅผ ๋ฐ๋ผ์ ๊ฒ์ฌ๋ฉ๋๋ค. ํ์ด ์ธ์ด๋ python3์ ์ฌ์ฉํฉ๋๋ค.
๋์ด๋: Medium
ํค์๋: Array, Sorting
๋ฌธ์
๋ฌธ์ ์๋ฌธ: https://leetcode.com/problems/h-index/description/?envType=study-plan-v2&envId=top-interview-150
์ ์ ๋ฐฐ์ด citations ์ด ์ฃผ์ด์ง ๋ H-index๋ฅผ ๋ฐํํด๋ผ
๋ฌธ์ ํ์ด
class Solution:
def hIndex(self, citations: List[int]) -> int:
citations.sort(reverse=True)
for i in range(len(citations)):
if citations[i] >= i+1:
continue
else:
return i
return i + 1
๋ฐ์ํ
'IN DEPTH CAKE > Supercoder' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++/LeetCode-Array] 56. Merge Intervals (2) | 2024.05.04 |
---|---|
[c++/LeetCode-Array] 162. Find Peak Element (1) | 2024.05.02 |
[์ฝ๋ฉ/LeetCode150-(10)] 45. Jump Game II (0) | 2023.08.22 |
[์ฝ๋ฉ/LeetCode150-(9)] 55. Jump Game (13) | 2023.08.22 |
[์ฝ๋ฉ/LeetCode150-(8)] Best Time to Buy and Sell Stock II (122) (0) | 2023.08.22 |