본문 바로가기

Amazon/Leetcode - etc

709. To Lower Case

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"



<SOLVE>

import java.util.*;
class Solution {
    public String toLowerCase(String str) {
            char[] result = new char[str.length()];
            for(int i=0; i<str.length(); i++){
                result[i] = str.toLowerCase().charAt(i);
            }
            //String res = new String();
            StringBuffer res = new StringBuffer();
            for (int i = 0; i < result.length; i++) {
                //res += Character.toString(result[i]);
                res.append(result[i]);
            }
            return res.toString();       
        }
}


'Amazon > Leetcode - etc' 카테고리의 다른 글