2412. 完成所有交易的初始最少钱数

2412. 完成所有交易的初始最少钱数


题目链接:2412. 完成所有交易的初始最少钱数

代码如下:

//参考链接:https://leetcode.cn/problems/minimum-money-required-before-transactions/solutions/1830862/by-endlesscheng-lvym
class Solution {
public:
	long long minimumMoney(vector<vector<int>>& transactions) {
		long long total_lose = 0;
		int mx = 0;
		for (auto& t : transactions) {
			total_lose += max(t[0] - t[1], 0);
			mx = max(mx, min(t[0], t[1]));
		}
		return total_lose + mx;
	}
};

你可能感兴趣的:(leetcode,c++)