Skip to content

Commit 62cd981

Browse files
committed
Solution as on 03-08-2022 10:45 pm
1 parent 1293ec2 commit 62cd981

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// 2357. Make Array Zero by Subtracting Equal Amounts
2+
3+
class Solution
4+
{
5+
public:
6+
int minimumOperations(vector<int> &nums)
7+
{
8+
9+
int count = 0;
10+
sort(nums.begin(), nums.end());
11+
12+
for (int i = 0; i < nums.size(); ++i)
13+
{
14+
if (nums[i] == 0)
15+
continue;
16+
else
17+
{
18+
int a = nums[i];
19+
for (int j = i; j < nums.size(); ++j)
20+
{
21+
// nums[j] -= nums[i];
22+
nums[j] -= a;
23+
}
24+
25+
cout << endl;
26+
27+
for (auto itr : nums)
28+
cout << itr << " ";
29+
30+
++count;
31+
32+
cout << endl;
33+
cout << count;
34+
}
35+
}
36+
return count;
37+
}
38+
};

0 commit comments

Comments
 (0)