[LeetCode] 434. Number of Segments in a String_Easy
2018-08-28 00:38 Johnson_强生仔仔 阅读(217) 评论(0) 编辑 收藏 举报Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.
Please note that the string does not contain any non-printable characters.
Example:
Input: "Hello, my name is John" Output: 5
Code
class Solution: def countSegments(self, s): return len(s.split())