709. To Lower Case
一、題目
Given a string s
, return the string after replacing every uppercase letter with the same lowercase letter.
Example 1:
Input: s = "Hello" Output: "hello"
Example 2:
Input: s = "here" Output: "here"
Example 3:
Input: s = "LOVELY" Output: "lovely"
Constraints:
1 <= s.length <= 100
s
consists of printable ASCII characters.
二、程式作法
/*use ascii letter*/
public class Solution
{
public string ToLowerCase(string s)
{
char[] cs = s.ToCharArray();
for (int i = 0; i < cs.Length; i++)
{
if (cs[i] >= 'A' && cs[i] <= 'Z')
cs[i] += ' ';
}
return new string(cs);
}
}
/*use ascii number*/
/*
public class Solution
{
public string ToLowerCase(string s)
{
char[] cs = s.ToCharArray();
for (int i = 0; i < cs.Length; i++)
{
if ((int)cs[i] >= 65 && (int)cs[i] <= 90)
cs[i] = (char)((int)cs[i] + 32);
}
return new string(cs);
}
}
*/
三、思路筆記
略