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: solution/3100-3199/3100.Water Bottles II/README_EN.md
+44-5Lines changed: 44 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,14 +65,14 @@ tags:
65
65
66
66
### Solution 1: Simulation
67
67
68
-
We can drink all the full water bottles at the beginning, so the initial amount of water we drink is `numBottles`. Then we continuously perform the following operations:
68
+
We can drink all the full water bottles at the beginning, so initially the amount of water we drink is $\textit{numBottles}$. Then, we repeatedly perform the following operations:
69
69
70
-
- If we currently have `numExchange` empty water bottles, we can exchange them for a full water bottle, after which the value of `numExchange` increases by 1. Then, we drink this bottle of water, the amount of water we drink increases by $1$, and the number of empty water bottles increases by $1$.
71
-
- If we currently do not have `numExchange` empty water bottles, then we can no longer exchange for water, at which point we can stop the operation.
70
+
- If we currently have $\textit{numExchange}$ empty bottles, we can exchange them for one full bottle. After the exchange, the value of $\textit{numExchange}$ increases by $1$. Then, we drink this bottle, increasing the total amount of water drunk by $1$, and the number of empty bottles increases by $1$.
71
+
- If we do not have $\textit{numExchange}$ empty bottles, we cannot exchange for more water and should stop.
72
72
73
-
We continuously perform the above operations until we can no longer exchange for water. The final amount of water we drink is the answer.
73
+
We repeat the above process until we can no longer exchange bottles. The total amount of water drunk is the answer.
74
74
75
-
The time complexity is $O(\sqrt{numBottles})$ and the space complexity is $O(1)$.
75
+
The time complexity is $O(\sqrt{n})$, where $n$ is the initial number of full bottles. The space complexity is $O(1)$.
0 commit comments