Skip to content

Commit a304f41

Browse files
committed
feat: resolved
1 parent 1d5aabd commit a304f41

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

to_lower_case/src/lib.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
pub struct Solution {}
2+
3+
impl Solution {
4+
pub fn to_lower_case(s: String) -> String {
5+
s.chars()
6+
.map(|c| match c {
7+
'A'..='Z' => (c as u8 - 'A' as u8 + 'a' as u8) as char,
8+
_ => c,
9+
})
10+
.collect()
11+
}
12+
}
13+
114
#[cfg(test)]
215
mod tests {
16+
use super::*;
17+
18+
fn ok(s: &str, expected: &str) {
19+
assert_eq!(Solution::to_lower_case(s.to_string()), expected.to_string());
20+
}
21+
22+
#[test]
23+
fn example_1() {
24+
ok("Hello", "hello");
25+
}
26+
27+
#[test]
28+
fn example_2() {
29+
ok("here", "here");
30+
}
31+
332
#[test]
4-
fn it_works() {
5-
assert_eq!(2 + 2, 4);
33+
fn example_3() {
34+
ok("LOVELY", "lovely");
635
}
736
}

0 commit comments

Comments
 (0)