Python | Leetcode Python题解之第434题字符串中的单词数
题目:
题解:
class Solution:def countSegments(self, s):segment_count = 0for i in range(len(s)):if (i == 0 or s[i - 1] == ' ') and s[i] != ' ':segment_count += 1return segment_count
题目:
题解:
class Solution:def countSegments(self, s):segment_count = 0for i in range(len(s)):if (i == 0 or s[i - 1] == ' ') and s[i] != ' ':segment_count += 1return segment_count