Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List, Union, Collection, Mapping, Optional
from abc import ABC, abstractmethod

class Solution:
def hIndex(self, citations: List[int]) -> int:

citations.sort(reverse=True)
len_cit:int = len(citations)
answer:int = 0

for i in range(len_cit):

if citations[i] >= i + 1:
answer = i + 1

return answer
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function hIndex(citations: number[]): number {
citations.sort((a, b) => b - a);
const lenCit: number = citations.length;
let answer: number = 0;

for (let i = 0; i < lenCit; i++) {
if (citations[i] >= i + 1) {
answer = i + 1;
}
}

return answer;
};
17 changes: 17 additions & 0 deletions tests/test_150_questions_round_23/test_11_h_index_round_23.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest
from src.my_project.interviews.top_150_questions_round_23\
.ex_11_h_index import Solution

class hIndexTestCase(unittest.TestCase):

def test_h_index_test_1(self):
solution = Solution()
output = solution.hIndex(citations = [3,0,6,1,5])
target = 3
self.assertEqual(output, target)

def test_h_index_test_2(self):
solution = Solution()
output = solution.hIndex(citations = [1,3,1])
target = 1
self.assertEqual(output, target)
Loading