Skip to content

Commit

Permalink
feat: 每日一题算法+面试
Browse files Browse the repository at this point in the history
  • Loading branch information
joywins-y committed Oct 30, 2023
1 parent 7c50317 commit d13e472
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/.vitepress/sidebar/algorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export default [
text: "260. 只出现一次的数字 III",
link: "/algorithm/260.single-number-iii",
},
{
text: "275. H 指数 II",
link: "/algorithm/275.h-index-ii",
},
{
text: "1155. 掷骰子等于目标和的方法数",
link: "/algorithm/1155.number-of-dice-rolls-with-target-sum",
Expand Down
16 changes: 16 additions & 0 deletions docs/.vitepress/sidebar/interview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ export default [
text: "23-10-26",
link: "/interview/daily-question/23-10-26",
},
{
text: "23-10-27",
link: "/interview/daily-question/23-10-27",
},
{
text: "23-10-28",
link: "/interview/daily-question/23-10-28",
},
{
text: "23-10-29",
link: "/interview/daily-question/23-10-29",
},
{
text: "23-10-30",
link: "/interview/daily-question/23-10-30",
},
],
},
{
Expand Down
56 changes: 56 additions & 0 deletions docs/algorithm/275.h-index-ii.md
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;
};
```
19 changes: 19 additions & 0 deletions docs/interview/daily-question/23-10.27.md
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.
19 changes: 19 additions & 0 deletions docs/interview/daily-question/23-10.30.md
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;
};
```

0 comments on commit d13e472

Please sign in to comment.