Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
Example 1:
Input: "Hello"
Output: "hello"
Example 2:
Input: "here"
Output: "here"
Example 3:
Input: "LOVELY"
Output: "lovely"
Runtime: 0 ms, faster than 100.00% of Rust online submissions for To Lower Case.
impl Solution {
pub fn to_lower_case(str: String) -> String {
let mut result = String::with_capacity(str.len());
for c in str.chars() {
let code = c as u8;
if code >= 65 && code <= 90 {
let newCode = code + 32;
result.push(newCode as char);
} else {
result.push(c);
}
}
result
}
}