To Lower Case

easy string

Problem

Return a copy of the string with every ASCII uppercase letter converted to lowercase.

Inputs = 'Hello'
Output'hello'
Only the four uppercase letters change.

def to_lower(s):
    return ''.join(chr(ord(c) + 32) if 'A' <= c <= 'Z' else c for c in s)
function toLowerCase(s) {
  let out = '';
  for (const c of s) out += (c >= 'A' && c <= 'Z') ? String.fromCharCode(c.charCodeAt(0) + 32) : c;
  return out;
}
String toLowerCase(String s) {
    char[] a = s.toCharArray();
    for (int i = 0; i < a.length; i++) if (a[i] >= 'A' && a[i] <= 'Z') a[i] += 32;
    return new String(a);
}
string toLowerCase(string s) {
    for (char& c : s) if (c >= 'A' && c <= 'Z') c += 32;
    return s;
}
Time: O(n) Space: O(n)