Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 847 Bytes

709. To Lower Case.md

File metadata and controls

39 lines (30 loc) · 847 Bytes

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

Example 1:

Input: "Hello"
Output: "hello"

Example 2:

Input: "here"
Output: "here"

Example 3:

Input: "LOVELY"
Output: "lovely"

Solution

  • mine
// O(n)Time O(n)Space
class Solution {
    public String toLowerCase(String str) {
        // A - Z  65-90  a:97   so  a = A + 32
        StringBuffer res = new StringBuffer();
        char [] resArray = str.toCharArray();
        for(int i = 0; i < resArray.length; i++){
            if(resArray[i] >= 65 && resArray[i] <= 90){
                resArray[i] += 32;
            }
            res.append(resArray[i]);
        }
        return res.toString();
    }
}