Number of Segments in a String

Problem Id: 434 Difficulty: Easy


Intuition

Solution


class Solution:
    def countSegments(self, s: str) -> int:
        if not s:
            return 0
        return len([c for c in s.split(' ') if c])