-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# 275. H 指数 II | ||
|
||
> 难度:<span style="color: #ffb800; font-weight: 500">中等</span> | ||
> | ||
> 地址:https://leetcode.cn/problems/h-index-ii/description/ | ||
给你一个整数数组 `citations` ,其中 `citations[i]` 表示研究者的第 `i` 篇论文被引用的次数,`citations` 已经按照 **升序排列** 。计算并返回该研究者的 h 指数。 | ||
|
||
[h 指数的定义](https://baike.baidu.com/item/H%E6%8C%87%E6%95%B0/9951340?fromtitle=h-index&fromid=3991452):h 代表“高引用次数”(high citations),一名科研人员的 `h` 指数是指他(她)的 (`n` 篇论文中)**总共**有 `h` 篇论文分别被引用了**至少** `h` 次。 | ||
|
||
请你设计并实现对数时间复杂度的算法解决此问题。 | ||
|
||
**示例 1:** | ||
|
||
> **<font color=#000>输入</font>**:`citations = [0,1,3,5,6]` | ||
> | ||
> **<font color=#000>输出</font>**:`3` | ||
> | ||
> **<font color=#000>解释</font>**:给定数组表示研究者总共有 `5` 篇论文,每篇论文相应的被引用了 `0, 1, 3, 5, 6` 次。 | ||
> 由于研究者有 `3` 篇论文每篇 **至少** 被引用了 `3` 次,其余两篇论文每篇被引用 **不多于** `3` 次,所以她的 _h_ 指数是 `3` 。 | ||
**示例 2:** | ||
|
||
> **<font color=#000>输入</font>**:`citations = [1,2,100]` | ||
> | ||
> **<font color=#000>输出</font>**:`2` | ||
**提示:** | ||
|
||
- `n == citations.length` | ||
- `1 <= n <= 10^5` | ||
- `0 <= citations[i] <= 1000` | ||
- `citations` 按 **升序排列** | ||
|
||
**题解:** | ||
|
||
```js | ||
/** | ||
* @param {number[]} citations | ||
* @return {number} | ||
*/ | ||
var hIndex = function (citations) { | ||
let len = citations.length; | ||
let left = 0; | ||
let right = len - 1; | ||
while (left <= right) { | ||
const mid = left + Math.floor((right - left) / 2); | ||
if (citations[mid] >= len - mid) { | ||
right = mid - 1; | ||
} else { | ||
left = mid + 1; | ||
} | ||
} | ||
return len - left; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 【淘宝】如何把字符串全部转化为小写格式 | ||
|
||
在 ES6+ 中,可直接使用原生 API String.prototype.toLowerCase() 实现。 | ||
|
||
如果手写实现,如下所示: | ||
|
||
```js | ||
const lowerCase = (str) => { | ||
let result = ""; | ||
for (let char of str) { | ||
const charAt = char.charCodeAt(); | ||
if (charAt <= "Z".charCodeAt() && charAt >= "A".charCodeAt()) { | ||
char = String.fromCharCode(charAt + 32); | ||
} | ||
result += char; | ||
} | ||
return result; | ||
}; | ||
``` |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 【淘宝】如何把字符串全部转化为小写格式 | ||
|
||
在 ES6+ 中,可直接使用原生 API String.prototype.toLowerCase() 实现。 | ||
|
||
如果手写实现,如下所示: | ||
|
||
```js | ||
const lowerCase = (str) => { | ||
let result = ""; | ||
for (let char of str) { | ||
const charAt = char.charCodeAt(); | ||
if (charAt <= "Z".charCodeAt() && charAt >= "A".charCodeAt()) { | ||
char = String.fromCharCode(charAt + 32); | ||
} | ||
result += char; | ||
} | ||
return result; | ||
}; | ||
``` |