2027. Minimum Moves to Convert String
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 56% Topics: String, Greedy
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def minimumMoves(self, s):
"""
:type s: str
:rtype: int
"""
result = i = 0
while i < len(s):
if s[i] == 'X':
result += 1
i += 3
else:
i += 1
return result
Solution from kamyu104/LeetCode-Solutions · MIT