Skip to content

Commit 105a4af

Browse files
committed
feat: add solutions to lc problem: No.0875
No.0875.Koko Eating Bananas
1 parent fac93e9 commit 105a4af

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

solution/0800-0899/0875.Koko Eating Bananas/README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656

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

59-
二分枚举速度值,找到能在 h 小时内吃完所有香蕉的最小速度值。
59+
二分枚举速度值,找到能在 $h$ 小时内吃完所有香蕉的最小速度值。
60+
61+
时间复杂度 $O(n\log m)$,空间复杂度 $O(1)$。其中 $n$ 是 `piles` 的长度,而 $m$ 是 `piles` 中的最大值。
6062

6163
<!-- tabs:start -->
6264

@@ -145,6 +147,28 @@ func minEatingSpeed(piles []int, h int) int {
145147
}
146148
```
147149

150+
### **TypeScript**
151+
152+
```ts
153+
function minEatingSpeed(piles: number[], h: number): number {
154+
let left = 1;
155+
let right = Math.max(...piles);
156+
while (left < right) {
157+
const mid = (left + right) >> 1;
158+
let s = 0;
159+
for (const x of piles) {
160+
s += Math.ceil(x / mid);
161+
}
162+
if (s <= h) {
163+
right = mid;
164+
} else {
165+
left = mid + 1;
166+
}
167+
}
168+
return left;
169+
}
170+
```
171+
148172
### **C#**
149173

150174
```cs

solution/0800-0899/0875.Koko Eating Bananas/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ func minEatingSpeed(piles []int, h int) int {
130130
}
131131
```
132132

133+
### **TypeScript**
134+
135+
```ts
136+
function minEatingSpeed(piles: number[], h: number): number {
137+
let left = 1;
138+
let right = Math.max(...piles);
139+
while (left < right) {
140+
const mid = (left + right) >> 1;
141+
let s = 0;
142+
for (const x of piles) {
143+
s += Math.ceil(x / mid);
144+
}
145+
if (s <= h) {
146+
right = mid;
147+
} else {
148+
left = mid + 1;
149+
}
150+
}
151+
return left;
152+
}
153+
```
154+
133155
### **C#**
134156

135157
```cs
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function minEatingSpeed(piles: number[], h: number): number {
2+
let left = 1;
3+
let right = Math.max(...piles);
4+
while (left < right) {
5+
const mid = (left + right) >> 1;
6+
let s = 0;
7+
for (const x of piles) {
8+
s += Math.ceil(x / mid);
9+
}
10+
if (s <= h) {
11+
right = mid;
12+
} else {
13+
left = mid + 1;
14+
}
15+
}
16+
return left;
17+
}

solution/0800-0899/0876.Middle of the Linked List/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, 以及 ans.next.next.next
4242

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

45-
“快慢指针”实现。
45+
**方法一:快慢指针**
46+
47+
定义快慢指针 `fast``slow`,初始时均指向链表的头结点。
48+
49+
快指针 `fast` 每次走两步,慢指针 `slow` 每次走一步。当快指针走到链表的尾部时,慢指针所指的结点即为中间结点。
50+
51+
时间复杂度 $O(n)$,空间复杂度 $O(1)$。其中 $n$ 是链表的长度。
4652

4753
<!-- tabs:start -->
4854

solution/0800-0899/0877.Stone Game/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Alice 先开始,只能拿前 5 颗或后 5 颗石子 。
5555

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

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

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

6262
<!-- tabs:start -->
6363

0 commit comments

Comments
 (0)