From 9361e527c36ef9aa9bc69484aa38656999f52eab Mon Sep 17 00:00:00 2001 From: ImAlpha Date: Tue, 4 Jul 2023 16:31:11 -0700 Subject: [PATCH] clears 50/78 tests --- Top150Interview/274H-Index.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Top150Interview/274H-Index.py diff --git a/Top150Interview/274H-Index.py b/Top150Interview/274H-Index.py new file mode 100644 index 0000000..d6aaf45 --- /dev/null +++ b/Top150Interview/274H-Index.py @@ -0,0 +1,28 @@ +def hIndex(citations): + """ + :type citations: List[int] + :rtype: int + """ + citations.sort() + h = citations[0] + count = 0 + newH = 0 + if len(citations) == 1: + if citations[0] == 0: + return 0 + else: + return 1 + for x in range(len(citations)): + if h == citations[x]: + newH = citations[x] + elif citations[x] > h and newH == 0: + newH = citations[x] + # print(newH) + print(newH) + return newH + +hIndex([3,0,6,1,5]) # 3 +# hIndex([1,3,1]) # 1 +# hIndex([0,1]) # 1 +# hIndex([1,2]) # 1 +# hIndex([2,1]) # 1 \ No newline at end of file