Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.0875
Browse files Browse the repository at this point in the history
No.0875.Koko Eating Bananas
  • Loading branch information
yanglbme committed Sep 11, 2022
1 parent fac93e9 commit 105a4af
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
26 changes: 25 additions & 1 deletion solution/0800-0899/0875.Koko Eating Bananas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@

**方法一:二分查找**

二分枚举速度值,找到能在 h 小时内吃完所有香蕉的最小速度值。
二分枚举速度值,找到能在 $h$ 小时内吃完所有香蕉的最小速度值。

时间复杂度 $O(n\log m)$,空间复杂度 $O(1)$。其中 $n$ 是 `piles` 的长度,而 $m$ 是 `piles` 中的最大值。

<!-- tabs:start -->

Expand Down Expand Up @@ -145,6 +147,28 @@ func minEatingSpeed(piles []int, h int) int {
}
```

### **TypeScript**

```ts
function minEatingSpeed(piles: number[], h: number): number {
let left = 1;
let right = Math.max(...piles);
while (left < right) {
const mid = (left + right) >> 1;
let s = 0;
for (const x of piles) {
s += Math.ceil(x / mid);
}
if (s <= h) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
}
```

### **C#**

```cs
Expand Down
22 changes: 22 additions & 0 deletions solution/0800-0899/0875.Koko Eating Bananas/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,28 @@ func minEatingSpeed(piles []int, h int) int {
}
```

### **TypeScript**

```ts
function minEatingSpeed(piles: number[], h: number): number {
let left = 1;
let right = Math.max(...piles);
while (left < right) {
const mid = (left + right) >> 1;
let s = 0;
for (const x of piles) {
s += Math.ceil(x / mid);
}
if (s <= h) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
}
```

### **C#**

```cs
Expand Down
17 changes: 17 additions & 0 deletions solution/0800-0899/0875.Koko Eating Bananas/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function minEatingSpeed(piles: number[], h: number): number {
let left = 1;
let right = Math.max(...piles);
while (left < right) {
const mid = (left + right) >> 1;
let s = 0;
for (const x of piles) {
s += Math.ceil(x / mid);
}
if (s <= h) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
}
8 changes: 7 additions & 1 deletion solution/0800-0899/0876.Middle of the Linked List/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, 以及 ans.next.next.next

<!-- 这里可写通用的实现逻辑 -->

“快慢指针”实现。
**方法一:快慢指针**

定义快慢指针 `fast``slow`,初始时均指向链表的头结点。

快指针 `fast` 每次走两步,慢指针 `slow` 每次走一步。当快指针走到链表的尾部时,慢指针所指的结点即为中间结点。

时间复杂度 $O(n)$,空间复杂度 $O(1)$。其中 $n$ 是链表的长度。

<!-- tabs:start -->

Expand Down
4 changes: 2 additions & 2 deletions solution/0800-0899/0877.Stone Game/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ Alice 先开始,只能拿前 5 颗或后 5 颗石子 。

设 $dp[i][j]$ 表示在石子堆 $[i,j]$ 中,当前玩家与另一个玩家的石子数量的最大差值。

若 $dp[0][n-1]>0$,说明当前玩家能赢得比赛。
若 $dp[0][n-1] \gt 0$,说明当前玩家能赢得比赛。

时间复杂度 $O(n^2)$。
时间复杂度 $O(n^2)$,空间复杂度 $O(n^2)$。其中 $n$ 是石子堆的数量

<!-- tabs:start -->

Expand Down

0 comments on commit 105a4af

Please sign in to comment.