funcmaximumWealth(accounts [][]int) (ans int) { for _, account := range accounts { sum := 0 for _, val := range account { sum += val } if sum > ans { ans = sum } } return }
[sol1-JavaScript]
1 2 3 4 5 6 7
var maximumWealth = function(accounts) { let maxWealth = -Number.MAX_VALUE; for (const account of accounts) { maxWealth = Math.max(maxWealth, account.reduce((a, b) => a + b)); } return maxWealth; };
[sol1-C]
1 2 3 4 5 6 7 8 9 10 11 12 13
#define MAX(a, b) ((a) > (b) ? (a) : (b))
intmaximumWealth(int** accounts, int accountsSize, int* accountsColSize){ int maxWealth = INT_MIN; for (int i = 0; i < accountsSize; i++) { int sum = 0; for (int j = 0; j < accountsColSize[0]; j++) { sum += accounts[i][j]; } maxWealth = MAX(maxWealth, sum); } return maxWealth; }