Length of Last Word
Given a string s
consisting of words and spaces, return the length of the last word in the string.
A word is a maximal substring consisting of non-space characters only.
Example 1:
1 | Input: s = "Hello World" |
Example 2:
1 | Input: s = " fly me to the moon " |
Example 3:
1 | Input: s = "luffy is still joyboy" |
个人解答:
时间复杂度:O(n)
空间复杂度:O(1)
1 | int lengthOfLastWord(string s) { |