Length of Last Word
Input: s = "Hello World"
Output: 5Input: s = " "
Output: 0Solutions
π Python
class Solution:
def lengthOfLastWord(self, s: str) -> int:
return len(s.rsplit(maxsplit=1)[-1]) if len(s.strip()) else 0π§ Cpp
Last updated