摘要:
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 阅读全文
摘要:
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()去除首尾 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文