-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLc_1672.java
More file actions
86 lines (63 loc) · 1.89 KB
/
Lc_1672.java
File metadata and controls
86 lines (63 loc) · 1.89 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Lc- 1672. Richest Customer Wealth
import java.util.ArrayList;
public class Lc_1672 {
public static void main(String[] args) {
/* ArrayList<ArrayList<Integer>> list = new ArrayList<>();
list.add(new ArrayList<>(Arrays.asList(1, 2, 3)));
list.add(new ArrayList<>(Arrays.asList(4, 5, 6)));
list.add(new ArrayList<>(Arrays.asList(7, 8, 9)));*/
int[][] list = {
{1,2,3},
{3,2,1}
};
System.out.println(maximumWealth(list));;
}
/* private static int maxSum(ArrayList<ArrayList<Integer>> list) {
ArrayList<Integer> accountData = new ArrayList<>();
//Array Sum
for(ArrayList<Integer> arr : list){
accountData.add(arraySum(arr));
}
return maximum(accountData);
}
private static Integer arraySum(ArrayList<Integer> arr) {
int sum = 0;
for(int i : arr){
sum+=i;
}
return sum;
}
private static int maximum(ArrayList<Integer> accountData) {
int max = Integer.MIN_VALUE;
for(int i : accountData){
if(i > max){
max = i;
}
}
return accountData.indexOf(max);
}*/
public static int maximumWealth(int[][] accounts) {
ArrayList<Integer> accountData = new ArrayList<>(100);
//Array Sum
for(int[] arr : accounts){
accountData.add(arraySum(arr));
}
return maximum(accountData);
}
private static int arraySum(int[] arr) {
int sum = 0;
for(int i : arr){
sum+=i;
}
return sum;
}
private static int maximum(ArrayList<Integer> accountData) {
int max = Integer.MIN_VALUE;
for(int i : accountData){
if(i > max){
max = i;
}
}
return accountData.indexOf(max);
}
}