936. capitalized
Chinese
English
Enter an English sentence, the first letter of each word into uppercase letters
Sample
Sample 1
输入: s = "i want to get an accepted"
输出: "I Want To Get An Accepted"
Sample 2
输入: s = "i jidls mdijf i lsidj i p l "
输出: "I Jidls Mdijf I Lsidj I P L "
Precautions
- This sentence may not be consistent with a sentence grammar rules.
- Sentence length or less
100
.
class Solution: "" " @param S: A String @return: A String After capitalizes The First Letter " "" '' ' general idea: 1 . First, a given initial value = P ' ' , if each cycle from ' ' At that time there are characters, indicating that a new character, this time to take a new full string, first in capital 2 given res, if the string is then capitalized, if not, directly spliced to res inside '' ' DEF capitalizesFirst (Self, S): RES = ' ' in Flag = False for I in S: # description is not empty IF I!= ' ' and Flag == False: i = i.upper() Flag = True elif i == ' ': Flag = False res += i return res