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
We use an array $d$ to record the denominations of the bills and an array $cnt$ to record the number of bills for each denomination.
87
+
We use an array $\textit{d}$ to record the denominations of the bills and an array $\textit{cnt}$ to record the number of bills for each denomination.
88
88
89
-
For the `deposit` operation, we only need to add the number of bills for the corresponding denomination. The time complexity is $O(1)$.
89
+
For the `deposit` operation, we simply add the number of bills to the corresponding denomination. The time complexity is $O(1)$.
90
90
91
-
For the `withdraw` operation, we enumerate the bills from largest to smallest denomination, taking out as many bills as possible without exceeding the $amount$. Then, we subtract the total value of the withdrawn bills from $amount$. If $amount$ is still greater than $0$ at the end, it means it's not possible to withdraw the $amount$ with the available bills, and we return $-1$. Otherwise, we return the number of bills withdrawn. The time complexity is $O(1)$.
91
+
For the `withdraw` operation, we enumerate the bills from largest to smallest denomination, taking out as many bills as possible without exceeding $\textit{amount}$. We then subtract the total value of the withdrawn bills from $\textit{amount}$. If $\textit{amount}$ is still greater than $0$ at the end, it means we cannot withdraw the requested amount, and we return $-1$. Otherwise, we return the number of withdrawn bills. The time complexity is $O(1)$.
92
92
93
93
<!-- tabs:start -->
94
94
@@ -97,22 +97,23 @@ For the `withdraw` operation, we enumerate the bills from largest to smallest de
0 commit comments