Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.

这个问题也没啥意思,绝不可能会面到

class Solution {
    public String toLowerCase(String str) {
        if(str == null || str.length() == 0)
            return str;

        char[] array = str.toCharArray();
        for(int i = 0; i < array.length; i++) {
            if(array[i] >= 'A' && array[i] <= 'Z')
                array[i] = (char) (array[i] - 'A' + 'a');
        }

        return String.valueOf(array);
    }
}

results matching ""

    No results matching ""