HTMLify

LeetCode - Number of Segments in a String - Python
Views: 16 | Author: abh
class Solution:
    def countSegments(self, s: str) -> int:
        n = 0
        f = True
        for c in s+" ":
            if c == " ":
                if not f:
                    n += 1
                f = True
            else:
                f = False
        return n

Comments