-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1672.c
More file actions
45 lines (44 loc) · 1.17 KB
/
1672.c
File metadata and controls
45 lines (44 loc) · 1.17 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
int maximumWealth(int** accounts, int accountsSize, int* accountsColSize)
{
int i;
int j;
int z;
int temp;
int *result;
i = 0;
j = 0;
z = 0;
temp = 0;
result = (int*)malloc(sizeof(int) * accountsSize);
while (i < accountsSize)
{
result[i] = 0;
while (j < accountsColSize[i])
{
result[i] = result[i] + accounts[i][j];
j++;
}
j = 0;
i++;
}
i = 0;
j = 1;
while (z < accountsSize * 2) // need this to make sure it moves all elements of the array (to compare them all with each other) and not just doing a comparison once
{ while (i < accountsSize - 1)
{
if (result[i] < result[j])
{
temp = result[i];
result[i] = result[j];
result[j] = temp;
}
i++;
j++;
}
i = 0;
j = 1;
z++;
}
temp = result[0];
return temp;
}