MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / min_flips

Function min_flips

1529-minimum-suffix-flips.rs:4–12  ·  view source on GitHub ↗
(target: String)

Source from the content-addressed store, hash-verified

2// 如果target从0开始,结果初始为0,从1,结果初始为1
3
4pub fn min_flips(target: String) -> i32 {
5 let mut prev = target.chars().nth(0).unwrap();
6 let mut ret = prev as i32 - '0' as i32;
7 for c in target.chars().collect::<Vec<char>>() {
8 if c != prev { ret += 1 }
9 prev = c;
10 }
11 ret
12}
13
14fn main() {
15 let target = "10111".to_string();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected