You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/g0301_0400/s0375_guess_number_higher_or_lower_ii/readme.md
+27-18Lines changed: 27 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -20,22 +20,25 @@ Given a particular `n`, return _the minimum amount of money you need to **guaran
20
20
21
21
**Output:** 16
22
22
23
-
**Explanation:** The winning strategy is as follows:
24
-
- The range is\[1,10\]. Guess 7.
25
-
- If this is my number, your total is $0. Otherwise, you pay $7.
26
-
- If my number is higher, the range is\[8,10\]. Guess 9.
27
-
- If this is my number, your total is $7. Otherwise, you pay $9.
28
-
- If my number is higher, it must be 10. Guess 10. Your total is $7 + $9 = $16.
29
-
- If my number is lower, it must be 8. Guess 8. Your total is $7 + $9 = $16.
30
-
- If my number is lower, the range is\[1,6\]. Guess 3.
31
-
- If this is my number, your total is $7. Otherwise, you pay $3.
32
-
- If my number is higher, the range is\[4,6\]. Guess 5.
33
-
- If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $5.
34
-
- If my number is higher, it must be 6. Guess 6. Your total is $7 + $3 + $5 = $15.
35
-
- If my number is lower, it must be 4. Guess 4. Your total is $7 + $3 + $5 = $15.
36
-
- If my number is lower, the range is\[1,2\]. Guess 1.
37
-
- If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $1.
38
-
- If my number is higher, it must be 2. Guess 2. Your total is $7 + $3 + $1 = $11. The worst case in all these scenarios is that you pay $16. Hence, you only need $16 to guarantee a win.
23
+
**Explanation:**
24
+
25
+
The winning strategy is as follows:
26
+
- The range is [1,10]. Guess 7.
27
+
- If this is my number, your total is $0. Otherwise, you pay $7.
28
+
- If my number is higher, the range is [8,10]. Guess 9.
29
+
- If this is my number, your total is $7. Otherwise, you pay $9.
30
+
- If my number is higher, it must be 10. Guess 10. Your total is $7 + $9 = $16.
31
+
- If my number is lower, it must be 8. Guess 8. Your total is $7 + $9 = $16.
32
+
- If my number is lower, the range is [1,6]. Guess 3.
33
+
- If this is my number, your total is $7. Otherwise, you pay $3.
34
+
- If my number is higher, the range is [4,6]. Guess 5.
35
+
- If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $5.
36
+
- If my number is higher, it must be 6. Guess 6. Your total is $7 + $3 + $5 = $15.
37
+
- If my number is lower, it must be 4. Guess 4. Your total is $7 + $3 + $5 = $15.
38
+
- If my number is lower, the range is [1,2]. Guess 1.
39
+
- If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $1.
40
+
- If my number is higher, it must be 2. Guess 2. Your total is $7 + $3 + $1 = $11.
41
+
The worst case in all these scenarios is that you pay $16. Hence, you only need $16 to guarantee a win.
39
42
40
43
**Example 2:**
41
44
@@ -51,8 +54,14 @@ Given a particular `n`, return _the minimum amount of money you need to **guaran
51
54
52
55
**Output:** 1
53
56
54
-
**Explanation:** There are two possible numbers, 1 and 2. - Guess 1. - If this is my number, your total is $0. Otherwise, you pay $1. - If my number is higher, it must be 2. Guess 2. Your total is $1. The worst case is that you pay $1.
57
+
**Explanation:**
58
+
59
+
There are two possible numbers, 1 and 2.
60
+
- Guess 1.
61
+
- If this is my number, your total is $0. Otherwise, you pay $1.
62
+
- If my number is higher, it must be 2. Guess 2. Your total is $1.