LeetCode 709. To Lower Case

题目描述 LeetCode 709

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"

题目解读

  • 输入一个字符串,将这个字符串中的大写字母转化为小写字母输出,然后返回转化后的字符串

解题思路

  • 依次循环,将大写字母转化为小写字母

Code

# include
# include

char* toLowerCase(char* str) 
{
    int i;
    int len;

    len = strlen(str);
    for (i = 0; i < len; i ++)
    {
        if ( str[i] >= 'A' && str[i] <= 'Z')
        {
            str[i] = str[i] + 32;
        }
    }
    return str;
}

int main()
{   
    char s[10] = {"HELLOdd"};
    char *temp;

    temp = toLowerCase(s);

    printf("%s\n", temp);
}
LeetCode 709. To Lower Case_第1张图片

思考

  • 简单题目...

你可能感兴趣的:(LeetCode 709. To Lower Case)