Skip to content

Commit e2c7492

Browse files
committed
feat: add new leetcode problem and update summary
1 parent c60e9c0 commit e2c7492

File tree

7 files changed

+117
-1
lines changed

7 files changed

+117
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [1884. ](https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors)
2+
3+
[English Version](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
None
10+
11+
## 解法
12+
13+
<!-- 这里可写通用的实现逻辑 -->
14+
15+
<!-- tabs:start -->
16+
17+
### **Python3**
18+
19+
<!-- 这里可写当前语言的特殊实现逻辑 -->
20+
21+
```python
22+
23+
```
24+
25+
### **Java**
26+
27+
<!-- 这里可写当前语言的特殊实现逻辑 -->
28+
29+
```java
30+
31+
```
32+
33+
### **...**
34+
35+
```
36+
37+
```
38+
39+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# [1884. Egg Drop With 2 Eggs and N Floors](https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors)
2+
3+
[中文文档](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README.md)
4+
5+
## Description
6+
7+
<p>You are given <strong>two identical</strong> eggs and you have access to a building with <code>n</code> floors labeled from <code>1</code> to <code>n</code>.</p>
8+
9+
<p>You know that there exists a floor <code>f</code> where <code>0 &lt;= f &lt;= n</code> such that any egg dropped at a floor <strong>higher</strong> than <code>f</code> will <strong>break</strong>, and any egg dropped <strong>at or below</strong> floor <code>f</code> will <strong>not break</strong>.</p>
10+
11+
<p>In each move, you may take an <strong>unbroken</strong> egg and drop it from any floor <code>x</code> (where <code>1 &lt;= x &lt;= n</code>). If the egg breaks, you can no longer use it. However, if the egg does not break, you may <strong>reuse</strong> it in future moves.</p>
12+
13+
<p>Return <em>the <strong>minimum number of moves</strong> that you need to determine <strong>with certainty</strong> what the value of </em><code>f</code> is.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong>Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> n = 2
20+
<strong>Output:</strong> 2
21+
<strong>Explanation:</strong> We can drop the first egg from floor 1 and the second egg from floor 2.
22+
If the first egg breaks, we know that f = 0.
23+
If the second egg breaks but the first egg didn&#39;t, we know that f = 1.
24+
Otherwise, if both eggs survive, we know that f = 2.
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> n = 100
31+
<strong>Output:</strong> 14
32+
<strong>Explanation:</strong> One optimal strategy is:
33+
- Drop the 1st egg at floor 9. If it breaks, we know f is between 0 and 8. Drop the 2nd egg starting
34+
from floor 1 and going up one at a time to find f within 7 more drops. Total drops is 1 + 7 = 8.
35+
- If the 1st egg does not break, drop the 1st egg again at floor 22. If it breaks, we know f is between 9
36+
and 21. Drop the 2nd egg starting from floor 10 and going up one at a time to find f within 12 more
37+
drops. Total drops is 2 + 12 = 14.
38+
- If the 1st egg does not break again, follow a similar process dropping the 1st egg from floors 34, 45,
39+
55, 64, 72, 79, 85, 90, 94, 97, 99, and 100.
40+
Regardless of the outcome, it takes at most 14 drops to determine f.
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= n &lt;= 1000</code></li>
48+
</ul>
49+
50+
51+
## Solutions
52+
53+
<!-- tabs:start -->
54+
55+
### **Python3**
56+
57+
```python
58+
59+
```
60+
61+
### **Java**
62+
63+
```java
64+
65+
```
66+
67+
### **...**
68+
69+
```
70+
71+
```
72+
73+
<!-- tabs:end -->

solution/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,7 @@
18941894
| [1881](https://leetcode-cn.com/problems/maximum-value-after-insertion) | [插入后的最大值](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README.md) | `贪心算法` | 中等 | |
18951895
| [1882](https://leetcode-cn.com/problems/process-tasks-using-servers) | [使用服务器处理任务](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README.md) | `` | 中等 | |
18961896
| [1883](https://leetcode-cn.com/problems/minimum-skips-to-arrive-at-meeting-on-time) | [准时抵达会议现场的最小跳过休息次数](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README.md) | `动态规划` | 困难 | |
1897+
| [1884](https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors) | [Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md) | `数学`,`二分查找`,`动态规划` | 中等 | |
18971898

18981899
## 版权
18991900

solution/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,7 @@ Press <kbd>Control</kbd>+<kbd>F</kbd>(or <kbd>Command</kbd>+<kbd>F</kbd> on the
18921892
| [1881](https://leetcode.com/problems/maximum-value-after-insertion) | [Maximum Value after Insertion](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README_EN.md) | `Greedy` | Medium | |
18931893
| [1882](https://leetcode.com/problems/process-tasks-using-servers) | [Process Tasks Using Servers](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README_EN.md) | `Heap` | Medium | |
18941894
| [1883](https://leetcode.com/problems/minimum-skips-to-arrive-at-meeting-on-time) | [Minimum Skips to Arrive at Meeting On Time](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README_EN.md) | `Dynamic Programming` | Hard | |
1895+
| [1884](https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors) | [Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md) | `Math`,`Binary Search`,`Dynamic Programming` | Medium | |
18951896

18961897
## Copyright
18971898

solution/result.json

+1-1
Large diffs are not rendered by default.

solution/summary.md

+1
Original file line numberDiff line numberDiff line change
@@ -1919,3 +1919,4 @@
19191919
- [1881.Maximum Value after Insertion](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README.md)
19201920
- [1882.Process Tasks Using Servers](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README.md)
19211921
- [1883.Minimum Skips to Arrive at Meeting On Time](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README.md)
1922+
- [1884.Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README.md)

solution/summary_en.md

+1
Original file line numberDiff line numberDiff line change
@@ -1919,3 +1919,4 @@
19191919
- [1881.Maximum Value after Insertion](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README_EN.md)
19201920
- [1882.Process Tasks Using Servers](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README_EN.md)
19211921
- [1883.Minimum Skips to Arrive at Meeting On Time](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README_EN.md)
1922+
- [1884.Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md)

0 commit comments

Comments
 (0)