Skip to content

Commit

Permalink
add 275
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Jul 9, 2019
1 parent ea62d4c commit bf97e7f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ LeetCode
|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|
|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|
|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|
|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|
|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|
|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|
|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|
|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|
Expand Down Expand Up @@ -437,4 +439,4 @@ LeetCode
|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|
|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|
|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|
c
|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|
16 changes: 16 additions & 0 deletions src/0275-H-Index-II/0275.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution
{
public:
int hIndex(vector<int>& citations)
{
int l = 0, n = citations.size(), r = n -1;
while (l < r)
{
int mid = (l + r + 1) >> 1;
if (citations[mid] <= n - mid) l = mid;
else r = mid - 1;
}
if (l < n and citations[l] < n - l) return n - l - 1;
return n - l;
}
};
15 changes: 15 additions & 0 deletions src/0275-H-Index-II/0275.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func hIndex(citations []int) int {
l, n, r := 0, len(citations), len(citations) - 1
for l < r {
mid := (l + r + 1) / 2
if citations[mid] <= n - mid {
l = mid
} else {
r = mid - 1
}
}
if l < n && citations[l] < n - l {
return n - l - 1
}
return n - l
}
12 changes: 12 additions & 0 deletions src/0275-H-Index-II/0275.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def hIndex(self, citations: List[int]) -> int:
l, n, r = 0, len(citations), len(citations)-1
while l < r:
mid = (l + r + 1) >> 1
if citations[mid] <= n - mid:
l = mid
else:
r = mid - 1
if l < n and n - l > citations[l]:
return n - l - 1
return n - l

0 comments on commit bf97e7f

Please sign in to comment.