My Python Solution


  • 0
    class Solution(object):
        def countSegments(self, s):
            ans, mark, cnt = 0, 0, 0
            for i in xrange(len(s)):
                if s[i] != ' ' and not mark:
                    cnt, mark = 1 + cnt, 1
                elif s[i] ==' ':
                    mark = 0
            return cnt 
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.