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/2400-2499/2412.Minimum Money Required Before Transactions/README_EN.md
+63-1
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ Thus, starting with money = 3, the transactions can be performed in any order.
65
65
66
66
### Solution 1: Greedy
67
67
68
-
First, we accumulate all the negative profits, denoted as $s$. Then we enumerate each transaction as the last transaction. If `transactions[i].x > transactions[i].y`, it means the current transaction is losing money, and this transaction has been calculated when we previously accumulated negative profits, so we update the answer with `s + transactions[i].y`; otherwise, we update the answer with `s + transactions[i].x`.
68
+
First, we accumulate all negative profits, denoted as $s$. Then, we enumerate each transaction $\text{transactions}[i] = [a, b]$ as the last transaction. If $a > b$, it means the current transaction is a loss, and this transaction has already been included when we accumulated the negative profits earlier. Therefore, we update the answer with $s + b$. Otherwise, we update the answer with $s + a$.
69
69
70
70
The time complexity is $O(n)$, where $n$ is the number of transactions. The space complexity is $O(1)$.
0 commit comments