摘要: class Solution: def lengthOfLastWord(self, s: str) -> int: count = 0 local_count = 0 for i in range(len(s)): if s[i] == ' ': local_count = 0 else: local_count += 1 count = local_count return count 阅读全文
posted @ 2019-08-23 21:03 我叫郑小白 阅读(131) 评论(0) 推荐(0) 编辑
摘要: class Solution: def reverseWords(self, s: str) -> str: if s == '': return s ls = s.split() # " " if ls == []: return '' result = '' for i in range(0, len(ls)): result += ls[-1 - i] + ' ' # strip()去除首尾 阅读全文
posted @ 2019-08-23 21:02 我叫郑小白 阅读(196) 评论(0) 推荐(0) 编辑
摘要: class Solution: def maxSubArray(self, nums: List[int]) -> int: if max(nums) < 0: return nums local_max, global_max = 0, 0 for num in nums: local_max = max(0, local_max + num) global_max = max(global_m 阅读全文
posted @ 2019-08-23 18:46 我叫郑小白 阅读(99) 评论(0) 推荐(0) 编辑
摘要: class Solution: def countAndSay(self, n: int) -> str: seq = "1" for i in range(n-1): seq = self.getNext(seq) return seq def getNext(self, seq): i, next_seq = 0, '' while i < len(seq): count = 1 while 阅读全文
posted @ 2019-08-23 18:29 我叫郑小白 阅读(94) 评论(0) 推荐(0) 编辑