Skip to content

Commit 2d9dfd4

Browse files
committed
participated in leetcode contest
1 parent 6e4ef70 commit 2d9dfd4

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

452. Minimum Number of Arrows to Burst Balloons.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
class Solution {
22
public:
3-
4-
53
struct mycomp {
64
bool operator() (const pair<int,int> &p1, const pair<int,int> &p2) {
75
return p1.first > p2.first;
@@ -29,17 +27,12 @@ class Solution {
2927
pair<int,int> top;
3028
pair<int,int> sec;
3129

32-
33-
3430
top = pq.top();
3531
pq.pop();
3632

3733
sec = pq.top();
3834
pq.pop();
3935

40-
// cout << top.first <<" " << top.second << endl;
41-
// cout << sec.first <<" " << sec.second << endl;
42-
4336
if (top.first <=sec.first && top.second >=sec.second)
4437
pq.push({sec.first, sec.second});
4538

@@ -53,14 +46,9 @@ class Solution {
5346

5447
}
5548

56-
57-
5849
if(pq.size() == 1)
5950
res.push_back(pq.top());
6051

61-
6252
return res.size();
63-
64-
6553
}
6654
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public:
3+
int minMoves(vector<int>& nums) {
4+
5+
int ans = 0;
6+
int mine = INT_MAX;
7+
int sum = 0;
8+
for(auto i:nums) {
9+
10+
mine = min(mine,i);
11+
sum += i;
12+
}
13+
14+
ans = sum - nums.size()*mine;
15+
return ans;
16+
}
17+
};
18+
19+
20+
/*
21+
22+
Addding 1 to n - 1 elements is the same is subtracting 1 from one element, w.r.t goal of making the elements in the array equal.
23+
So, best way to do this is make all the elements in the array equal to the min element.
24+
sum(array) - n * minimum
25+
26+
*/

Non-leetcode/add two vectors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)