Skip to content

Commit 11f287c

Browse files
committed
Time: 5 ms (14.89%), Space: 12.2 MB (67.52%) - LeetHub
1 parent a0dca09 commit 11f287c

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
class Solution {
22
public:
33
int minChanges(string s) {
4-
int ans = 0;
5-
int n = s.size();
6-
for (int i = 0; i < n; i++) {
7-
int cnt = 1;
8-
int j = i + 1;
9-
while (j < n && s[j] == s[i]) j++, cnt++;
10-
ans += (cnt & 1);
11-
i = j;
12-
if (cnt % 2 == 0) i--;
4+
int changes = 0;
5+
for (int i = 0; i < s.size(); i += 2) {
6+
if (i + 1 < s.size() && s[i] != s[i + 1]) {
7+
changes++;
8+
}
139
}
14-
return ans;
10+
return changes;
1511
}
16-
};
12+
};

0 commit comments

Comments
 (0)