tutorialcup
To Lower Case Leetcode Solution
The problem To Lower Case Leetcode Solution provides us with a string and asks us to convert all the upper case alphabets into lower case alphabets. We are required to convert all the upper case or lower case alphabets into lower case characters. So, the problem seems simple but before diving into the solution. We take a look at a few examples.
"Hello"
"hello"
Explanation: The input has an upper case alphabet 'H' which is converted into the lower-case alphabet 'h'. The other characters "ello" stay the same and we do not need to convert them.
"here"
"here"
Explanation: Since all the alphabets in the input are lower case characters. We do not need to change any of the characters and can return the input without any modification.
Approach using in-built functions
The problem To Lower Case Leetcode Solution asked us to simply convert the upper case character to the lower case character. This operation can be easily done using in-built functions in programming languages. So, we can use tolower() in C++, or toLowerCase() in Java. Using these functions, we only need to pass the given string as input. Then we get the string with all characters in lower case.
Code
C++ code for To Lower Case Leetcode Solution
#include
using namespace std;
string toLowerCase(string str) {
transform(str.begin(), str.end(), str.begin(), (unsigned char c){ return std::tolower(c); });
return str;
}
int main(){
cout
www.tutorialcup.com/leetcode-solutions/to-lower-case-leet...
To Lower Case Leetcode Solution
The problem To Lower Case Leetcode Solution provides us with a string and asks us to convert all the upper case alphabets into lower case alphabets. We are required to convert all the upper case or lower case alphabets into lower case characters. So, the problem seems simple but before diving into the solution. We take a look at a few examples.
"Hello"
"hello"
Explanation: The input has an upper case alphabet 'H' which is converted into the lower-case alphabet 'h'. The other characters "ello" stay the same and we do not need to convert them.
"here"
"here"
Explanation: Since all the alphabets in the input are lower case characters. We do not need to change any of the characters and can return the input without any modification.
Approach using in-built functions
The problem To Lower Case Leetcode Solution asked us to simply convert the upper case character to the lower case character. This operation can be easily done using in-built functions in programming languages. So, we can use tolower() in C++, or toLowerCase() in Java. Using these functions, we only need to pass the given string as input. Then we get the string with all characters in lower case.
Code
C++ code for To Lower Case Leetcode Solution
#include
using namespace std;
string toLowerCase(string str) {
transform(str.begin(), str.end(), str.begin(), (unsigned char c){ return std::tolower(c); });
return str;
}
int main(){
cout
www.tutorialcup.com/leetcode-solutions/to-lower-case-leet...