Skip to content

Commit b539ea7

Browse files
authored
refactor(solutions/delete_prefix): simpler code using built-in method
1 parent a38b2f9 commit b539ea7

File tree

1 file changed

+1
-11
lines changed
  • solutions/delete_prefix/src

1 file changed

+1
-11
lines changed

solutions/delete_prefix/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,7 @@
88
// delete_prefix("not", "win");
99

1010
pub fn delete_prefix<'a, 'b>(prefix: &'b str, s: &'a str) -> Option<&'a str> {
11-
if prefix.len() > s.len() {
12-
return None;
13-
}
14-
let mut char_s = s.chars();
15-
16-
for char_prefix in prefix.chars() {
17-
if char_prefix != char_s.next()? {
18-
return None;
19-
}
20-
}
21-
Some(&s[prefix.len()..])
11+
s.strip_prefix(prefix)
2212
}
2313

2414
#[cfg(test)]

0 commit comments

Comments
 (0)