Skip to content

Commit 4d67380

Browse files
committed
Add solution #2027
1 parent 30d77fb commit 4d67380

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 2027. Minimum Moves to Convert String
3+
* https://leetcode.com/problems/minimum-moves-to-convert-string/
4+
* Difficulty: Easy
5+
*
6+
* You are given a string s consisting of n characters which are either 'X' or 'O'.
7+
*
8+
* A move is defined as selecting three consecutive characters of s and converting them
9+
* to 'O'. Note that if a move is applied to the character 'O', it will stay the same.
10+
*
11+
* Return the minimum number of moves required so that all the characters of s are
12+
* converted ]to 'O'.
13+
*/
14+
15+
/**
16+
* @param {string} s
17+
* @return {number}
18+
*/
19+
var minimumMoves = function(s) {
20+
return s.match(/X.{0,2}/g)?.length ?? 0;
21+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
2000|[Reverse Prefix of Word](./2000-reverse-prefix-of-word.js)|Easy|
278278
2011|[Final Value of Variable After Performing Operations](./2011-final-value-of-variable-after-performing-operations.js)|Easy|
279279
2016|[Maximum Difference Between Increasing Elements](./2016-maximum-difference-between-increasing-elements.js)|Easy|
280+
2027|[Minimum Moves to Convert String](./2027-minimum-moves-to-convert-string.js)|Easy|
280281
2047|[Number of Valid Words in a Sentence](./2047-number-of-valid-words-in-a-sentence.js)|Easy|
281282
2053|[Kth Distinct String in an Array](./2053-kth-distinct-string-in-an-array.js)|Medium|
282283
2085|[Count Common Words With One Occurrence](./2085-count-common-words-with-one-occurrence.js)|Easy|

0 commit comments

Comments
 (0)