LintCode: Lowercase to Uppercase II

Lowercase to Uppercase II



Similar Problems:


Description
Implement an upper method to convert all characters in a string to uppercase.

You should ignore the characters not in alphabet.

Example

Given "abc", return "ABC".

Given "aBc", return "ABC".

Given "abC12", return "ABC12".

Github: code.dennyzhang.com

Credits To: lintcode.com

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


  • Solution:
// Blog link: https://code.dennyzhang.com/lowercase-to-uppercase-ii
// Basic Ideas:
// Complexity: Time O(n), Space O(n)
/**
 * @param str: A string
 * @return: A string
 */
import "strings"
func lowercaseToUppercase2 (str string) string {
    res := []string{}
    offset := 'A'-'a'
    for _, ch := range str {
        if ch >= 'a' && ch <= 'z' { ch += offset }
        res = append(res, string(ch))
    }
    return strings.Join(res, "")
}
linkedin
github
slack

Share It, If You Like It.

Leave a Reply

Your email address will not be published.