题目: https://leetcode.com/problems/number-of-segments-in-a-string/
难度:
Easy
作弊神器Python
class Solution(object):
def countSegments(self, s):
"""
:type s: str
:rtype: int
"""
return len(s.split())
不过对于比如C++这种语言来说,应该是O(N),扫一圈应该也能得到正确答案
总之拿Python做string的题目就是作弊啊