Skip to content

Commit 497d449

Browse files
authored
Create minimum-moves-to-convert-string.cpp
1 parent a13d83f commit 497d449

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int minimumMoves(string s) {
7+
int result = 0;
8+
for (int i = 0; i < size(s); i += (s[i] == 'X') ? 3 : 1) {
9+
result += (s[i] == 'X');
10+
}
11+
return result;
12+
}
13+
};

0 commit comments

Comments
 (0)