Skip to content

Commit bf97e7f

Browse files
add 275
1 parent ea62d4c commit bf97e7f

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ LeetCode
215215
|0263|[Ugly Number](https://leetcode.com/problems/ugly-number/) | c | [c++](./src/0263-Ugly-Number/0263.cpp) |[python](./src/0263-Ugly-Number/0263.py)|||Easy|
216216
|0264|[Ugly Number II](https://leetcode.com/problems/ugly-number-ii/) | c | [c++](./src/0264-Ugly-Number-II/0264.cpp) |[python](./src/0264-Ugly-Number-II/0264.py)|||Medium|
217217
|0268|[Missing Number](https://leetcode.com/problems/missing-number/) | c | [c++](./src/0268-Missing-Number/0268.cpp) |[python](./src/0268-Missing-Number/0268.py)|||Easy|
218+
|0274|[H-Index](https://leetcode.com/problems/h-index/) | c | [c++](./src/0274-H-Index/0274.cpp) |[python](./src/0274-H-Index/0274.py)|[go](./src/0274-H-Index/0274.go)||Medium|
219+
|0275|[H-Index](https://leetcode.com/problems/h-index-ii/) | c | [c++](./src/0275-H-Index-II/0275.cpp) |[python](./src/0275-H-Index-II/0275.py)|[go](./src/0275-H-Index-II/0275.go)||Medium|
218220
|0279|[Perfect Squares](https://leetcode.com/problems/perfect-squares/) | c | [c++](./src/0279-Perfect-Squares/0279.cpp) |[python](./src/0279-Perfect-Squares/0279.py)|||Medium|
219221
|0283|[Move Zeroes](https://leetcode.com/problems/move-zeroes/) | c | [c++](./src/0283-Move-Zeroes/0283.cpp) |[python](./src/0283-Move-Zeroes/0283.py)|||Easy|
220222
|0287|[Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) | c | [c++](./src/00287-Find-the-Duplicate-Number/0287.cpp) |[python](./src/0287-Find-the-Duplicate-Number/0287.py)|||Medium|
@@ -437,4 +439,4 @@ LeetCode
437439
|1103|[Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people/) | c | [c++](./src/1103-Distribute-Candies-to-People/1103.cpp) |[python](./src/1103-Distribute-Candies-to-People/1103.py)|[go](./src/1103-Distribute-Candies-to-People/1103.go)||Easy|
438440
|1104|[Path In Zigzag Labelled Binary Tree](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/) | c | [c++](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.cpp) |[python](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.py)|[go](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.go)||Easy|
439441
|1105|[Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves/) | c | [c++](./src/1105-Filling-Bookcase-Shelves/1105.cpp) |[python](./src/1105-Filling-Bookcase-Shelves/1105.py)|[go](./src/1105-Filling-Bookcase-Shelves/1105.go)||Medium|
440-
c
442+
|1106|[Parsing A Boolean Expression](https://leetcode.com/problems/parsing-a-boolean-expression/) | c | [c++](./src/1106-Parsing-A-Boolean-Expression/1106.cpp) |[python](./src/1106-Parsing-A-Boolean-Expression/1106.py)|[go](./src/1106-Parsing-A-Boolean-Expression/1106.go)||Hard|

src/0275-H-Index-II/0275.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution
2+
{
3+
public:
4+
int hIndex(vector<int>& citations)
5+
{
6+
int l = 0, n = citations.size(), r = n -1;
7+
while (l < r)
8+
{
9+
int mid = (l + r + 1) >> 1;
10+
if (citations[mid] <= n - mid) l = mid;
11+
else r = mid - 1;
12+
}
13+
if (l < n and citations[l] < n - l) return n - l - 1;
14+
return n - l;
15+
}
16+
};

src/0275-H-Index-II/0275.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func hIndex(citations []int) int {
2+
l, n, r := 0, len(citations), len(citations) - 1
3+
for l < r {
4+
mid := (l + r + 1) / 2
5+
if citations[mid] <= n - mid {
6+
l = mid
7+
} else {
8+
r = mid - 1
9+
}
10+
}
11+
if l < n && citations[l] < n - l {
12+
return n - l - 1
13+
}
14+
return n - l
15+
}

src/0275-H-Index-II/0275.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def hIndex(self, citations: List[int]) -> int:
3+
l, n, r = 0, len(citations), len(citations)-1
4+
while l < r:
5+
mid = (l + r + 1) >> 1
6+
if citations[mid] <= n - mid:
7+
l = mid
8+
else:
9+
r = mid - 1
10+
if l < n and n - l > citations[l]:
11+
return n - l - 1
12+
return n - l

0 commit comments

Comments
 (0)