LeetCode—709

Approach

# 把字串裡的大寫字母轉成小寫字母
To check if it is a upper_case alphabet and change it to lower_case alphabet.

Time Complexity

# n = length of string
O(n)

Space Complexity

# n = length of string
O(n)

Code

class Solution {
public:
    string toLowerCase(string s) {
        int l = s.size();

        for (int i = 0 ; i < l ; i++) {
            if (s[i] - 'A' >= 0 && s[i] - 'Z' <= 0) {
                s[i] = s[i] - 'A' + 'a';
            }
        }

        return s;
    }
};