Skip to content

Commit 71484df

Browse files
committed
https://leetcode.cn/problems/minimum-changes-to-make-alternating-binary-string
1 parent 54e9619 commit 71484df

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/minimum-changes-to-make-alternating-binary-string
49+
4850
https://leetcode.cn/problems/sum-of-all-odd-length-subarrays
4951

5052
https://leetcode.cn/problems/combination-sum-iv/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function minOperations(s: string): number {
2+
const res = Array.prototype.reduce.call(
3+
s,
4+
//@ts-ignore
5+
(p: number, c: string, i: number) => p + Number(i % 2 === Number(c)),
6+
0
7+
) as number;
8+
return Math.min(res, s.length - res);
9+
}
10+
export default minOperations;

0 commit comments

Comments
 (0)