Algorithm


Problem Name: 709. To Lower Case

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.
 

Code Examples

#1 Code Example with Java Programming

Code - Java Programming


class Solution {
  public String toLowerCase(String s) {
    return s.chars().mapToObj(c -> (char) c).map(Character::toLowerCase).map(String::valueOf)
        .collect(Collectors.joining());
  }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
s = "Hello"

Output

x
+
cmd
"hello"

#2 Code Example with Python Programming

Code - Python Programming


class Solution:
    def toLowerCase(self, str): 
        return "".join(chr(ord(c) + 32) if 65 <= ord(c) <= 90 else c for c in str)
Copy The Code & Try With Live Editor

Input

x
+
cmd
s = "Hello"

Output

x
+
cmd
"hello"

#3 Code Example with C# Programming

Code - C# Programming


namespace LeetCode
{
    public class _0709_ToLowerCase
    {
        public string ToLowerCase(string str)
        {
            return str.ToLower();
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
s = "here"

Output

x
+
cmd
"here"
Advertisements

Demonstration


Previous
#707 Leetcode Design Linked List Solution in C, C++, Java, JavaScript, Python, C# Leetcode
Next
#710 Leetcode Random Pick with Blacklist Solution in C, C++, Java, JavaScript, Python, C# Leetcode