LeetCode:Richest Customer Wealth
Question
You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has.
A customer’s wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.
Solution #1
def maximum_wealth(accounts)
maximum = 0
accounts.each do |account|
maximum = account.sum if account.sum > maximum
end
maximum
end
Solution #2
def maximum_wealth(accounts)
accounts.map {|account| account.sum}.max
end
Comments