euisblue
1672. Richest Customer Wealth

C++

1/* 2 * Runtime: 12 ms, faster than 39.22% 3 * Memory Usage: 8.1 MB, less than 60.83% 4 */ 5class Solution { 6 public: 7 int maximumWealth(vector<vector<int>>& accounts) { 8 int max = -1; 9 for(int i=0; i<accounts.size(); ++i) { 10 int sum = 0; 11 for(int j=0; j<accounts[i].size(); ++j) { 12 sum += accounts[i][j]; 13 } 14 max = sum > max ? sum : max; 15 } 16 return max; 17 } 18};

JavaScript

1/** 2 * Runtime: 80 ms, faster than 56.45% 3 * Memory Usage: 38.7 MB, less than 35.23% 4 */ 5var maximumWealth = function(accounts) { 6 let max = 0; 7 accounts.forEach((bank) => { 8 let sum = 0; 9 bank.forEach((money) => { 10 sum += money; 11 }); 12 max = sum > max ? sum : max; 13 }); 14 15 return max; 16};

Ruby

1# Runtime: 52 ms, faster than 74.77% 2# Memory Usage: 209.8 MB, less than 96.73% 3def maximum_wealth(accounts) 4 max = 0 5 6 accounts.each do |bank| 7 sum = 0 8 bank.each do |money| 9 sum += money 10 end 11 max = sum > max ? sum : max 12 end 13 14 max 15end