-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2938.cpp
38 lines (32 loc) · 828 Bytes
/
2938.cpp
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
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
class Solution {
public:
long long minimumSteps(string s) {
int s_size = s.size();
long long steps = 0;
int right = s_size - 1;
for (int i = s_size - 1; i >= 0; i--) {
if (s[i] == '1') {
steps += right - i;
right--;
}
}
return steps;
}
};
int main() {
Solution solution;
string test1 = "1111";
string test2 = "0110";
string test3 = "0101";
string test4 = "101";
assert(solution.minimumSteps(test1) == 0);
assert(solution.minimumSteps(test2) == 2);
assert(solution.minimumSteps(test3) == 1);
assert(solution.minimumSteps(test4) == 1);
cout << "All tests passed!" << endl;
return 0;
}