Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.

 

Example 1:

Input: 

Example 2:

Input: 

Example 3:

Input: 

 

 1 class Solution {
 2 public:
 3     string toLowerCase(string str) {
 4         string res;
 5         for (int i = 0; i < str.length(); i++) {
 6             if (str[i] >= 'A' && str[i] <= 'Z') {
 7                 res += 'a' + (str[i] - 'A');
 8             } else {
 9                 res += str[i];
10             }
11         }
12         return res;
13     }
14 };

 

相关文章:

  • 2021-09-09
  • 2022-01-28
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-10-19
猜你喜欢
  • 2021-11-22
  • 2021-10-23
  • 2021-10-10
  • 2021-12-19
  • 2022-01-15
  • 2022-02-03
  • 2021-10-08
相关资源
相似解决方案