Skip to content

Commit 76fbb9f

Browse files
committed
Add C++ 16 17 18 Solution
1 parent a94b0b0 commit 76fbb9f

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

Problems/.DS_Store

2 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int minimumSum(int num) {
4+
vector<int> v {};
5+
while(num){
6+
v.push_back(num % 10);
7+
num /= 10;
8+
}
9+
10+
sort(v.begin(), v.end());
11+
12+
vector<int> a(2, 0);
13+
for (int i = 0; i < v.size(); i++)
14+
{
15+
a[i % 2] = a[i % 2] * 10 + v[i];
16+
}
17+
return a[0] + a[1];
18+
}
19+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int balancedStringSplit(string s) {
4+
int ans = 0;
5+
int cpt = 0;
6+
for (auto& c: s)
7+
{
8+
if (c == 'R') cpt ++;
9+
else cpt --;
10+
11+
if (cpt == 0) ans ++;
12+
}
13+
return ans;
14+
}
15+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
4+
5+
int m = flowerbed.size();
6+
if (n == 0) return true;
7+
int sum = 0;
8+
for (int j = 0; j < m; j++)
9+
{
10+
if ((j==0 or flowerbed[j-1] == 0) and (j == m-1 or flowerbed[j+1] == 0) and flowerbed[j] == 0)
11+
{
12+
flowerbed[j] = 1;
13+
sum++;
14+
}
15+
}
16+
17+
return sum >= n;
18+
}
19+
};

0 commit comments

Comments
 (0)