Leetcode: To Lower Case

To Lower Case

Similar Problems:

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

Github: code.dennyzhang.com

Credits To: leetcode.com

Leave me comments, if you have better ways to solve.

  • Solution:
// Blog link: https://code.dennyzhang.com/to-lower-case
// Basic Ideas
// Complexity: Time O(n), Space O(n)
func toLowerCase(str string) string {
    var res string
    for _, ch := range str {
        b := byte(ch) 
        if b >= byte('A') && b<=byte('Z') {
            res += string(b+byte('a')-byte('A'))
                } else {
                        res += string(ch)
        return res

Share It, If You Like It.

Leave a Reply

Your email address will not be published.