{"id":178,"date":"2018-05-26T22:16:17","date_gmt":"2018-05-26T14:16:17","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=178"},"modified":"2018-11-27T17:16:53","modified_gmt":"2018-11-27T09:16:53","slug":"434-number-of-segments-in-a-string","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=178","title":{"rendered":"434. Number of Segments in a String"},"content":{"rendered":"<p>Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.<\/p>\n<p>Please note that the string does not contain any\u00a0<b>non-printable<\/b>\u00a0characters.<\/p>\n<p><b>Example:<\/b><\/p>\n<pre><b>Input:<\/b> \"Hello, my name is John\"\r\n<b>Output:<\/b> 5<\/pre>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution:\r\n    def countSegments(self, s):\r\n        &quot;&quot;&quot;\r\n        :type s: str\r\n        :rtype: int\r\n        &quot;&quot;&quot;\r\n        a = s.split(&quot; &quot;)\r\n        result = 0\r\n        for i in a:\r\n            if i:\r\n                result += 1\r\n        return result\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Count the number of segments in a string, where a segme<a href=\"https:\/\/www.ccagml.com\/?p=178\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">434. Number of Segments in a String<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/178"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=178"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/178\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}