Given a string s
, return the string after replacing every uppercase letter with the same lowercase letter.
Example 1:
Input: s = "Hello"
Output: "hello"
Example 2:
Input: s = "here"
Output: "here"
Example 3:
Input: s = "LOVELY"
Output: "lovely"
Constraints:
1 <= s.length <= 100
s
consists of printable ASCII characters.
solution
Runtime: 0 ms, faster than 100.00% of C++ online submissions for To Lower Case.
Memory Usage: 6.2 MB, less than 55.22% of C++ online submissions for To Lower Case.
class Solution {
public:
string toLowerCase(string s) {
char ch;
for(int i=0;i<s.length();i++)
{
if(s[i]>='A'&&s[i]<='Z')
{
ch=s[i];
ch+=32;
s[i]=ch;
}
}
return s;
}
};
No comments:
Post a Comment