20170223-LeetCode_434_Number of Segments in a String
2017-02-23 09:49
471 查看
1.Description
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
2.Solution
#20170223 class Solution(object): def countSegments(self, s): """ :type s: str :rtype: int """ s,count=s.strip()+' ',0 for i in range(len(s)-1): if s[i]!=' ' and s[i+1]==' ': count+=1 return count
![](http://blog.csdn.net/u010105243/article/details/index_files/ad57ad2b-aa33-42b5-8a22-3fb5d776a7c6.png)
3.思路
!’ ‘+’ ‘这样的结构意味着有一个连续的字符出现相关文章推荐
- Leetcode Number of Segments in a String 434
- 20170223-leetcode-091-Number of Segments in a String
- Leetcode 434 Number of Segments in a String
- Leetcode 434 Number of Segments in a String
- leetcode 434- Number of Segments in a String
- leetcode 434[easy]---Number of Segments in a String
- LeetCode434 Number of Segments in a String java and python solution
- Leetcode: Number of Segments in a String
- LeetCode Number of Segments in a String
- 434_Number_of_Segments_in_a_String
- leetcode oj java Number of Segments in a String
- [LeetCode] Number of Segments in a String 字符串中的分段数量
- leetcode[Number of Segments in a String]//待整理多种解法
- 【LeetCode】Number of Segments in a String 解题报告
- 434 Number of Segments in a String
- LeetCode : Number of Segments in a String
- LEETCODE--Number of Segments in a String
- Leetcode Number of Segments in a String
- String-434-Number of Segments in a String
- 【Leetcode】【python】Number of Segments in a String