LeetCode 709: To Lower Case Solution
Master LeetCode problem 709 (To Lower Case), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.
709. To Lower Case
Problem Explanation
Explanation
To solve this problem, we can iterate over the characters of the input string s. For each character, we check if it is an uppercase letter. If it is, we convert it to lowercase using the ASCII values. Finally, we return the modified string.
- Time complexity: O(n), where n is the length of the input string
s. - Space complexity: O(n), for the output string.
Solution Code
class Solution {
public String toLowerCase(String s) {
StringBuilder sb = new StringBuilder();
for (char c : s.toCharArray()) {
if (c >= 'A' && c <= 'Z') {
sb.append((char)(c + 32));
} else {
sb.append(c);
}
}
return sb.toString();
}
}Try It Yourself
Loading code editor...
Related LeetCode Problems
Frequently Asked Questions
How to solve LeetCode 709 (To Lower Case)?
This page provides optimized solutions for LeetCode problem 709 (To Lower Case) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.
What is the time complexity of LeetCode 709 (To Lower Case)?
The time complexity for LeetCode 709 (To Lower Case) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.
Can I run code for LeetCode 709 on DevExCode?
Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 709 in Java, C++, or Python.