All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0701_0800.s0709_to_lower_case.Solution Maven / Gradle / Ivy

There is a newer version: 1.38
Show newest version
package g0701_0800.s0709_to_lower_case;

// #Easy #String #Programming_Skills_I_Day_9_String
// #2022_03_23_Time_1_ms_(71.74%)_Space_42_MB_(52.94%)

/**
 * 709 - To Lower Case\.
 *
 * Easy
 *
 * 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.
**/
public class Solution {
    public String toLowerCase(String s) {
        char[] c = s.toCharArray();
        for (int i = 0; i < s.length(); i++) {
            if (c[i] <= 'Z' && c[i] >= 'A') {
                c[i] = (char) (c[i] - 'A' + 'a');
            }
        }
        return new String(c);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy