Python without split()


  • 0
    class Solution(object):
        def countSegments(self, s):
            """
            :type s: str
            :rtype: int
            """
            re = 0
            mark = True
            for i in s:
                if i != " ": 
                    re += mark
                    mark = False
                else:
                    mark = True
            return re
    

Log in to reply
 

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