-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRighestWealth.js
More file actions
33 lines (29 loc) · 976 Bytes
/
RighestWealth.js
File metadata and controls
33 lines (29 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/***ou 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. */
var maximumWealth = function (accounts) {
let res = 0,
i = 0;
while (i < accounts.length) {
let temp = 0,
j = 0;
while (j < accounts[i].length) {
temp += accounts[i][j];
j++;
}
res = Math.max(res, temp);
i++;
}
return res;
};
//another solution
var maximumWealth = function (accounts) {
let array = accounts.map((x) => x.reduce((a, b) => a + b));
return Math.max(...array);
};
accounts = [
[1, 2, 3],
[3, 2, 1],
];
console.log(maximumWealth(accounts));