434 Number of Segments in a String
Input:
"Hello, my name is John"
Output:
5class Solution:
def countSegments(self, s):
"""
:type s: str
:rtype: int
"""
split_str = s.split()
return len(split_str)
obj = Solution()
assert(obj.countSegments("kasjd asdj, adkja askjd") == 4)
assert(obj.countSegments(" ") == 0)
assert(obj.countSegments("") == 0)Last updated