摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
posted @ 2020-05-09 15:05 星海寻梦233 阅读(64) 评论(0) 推荐(0) 编辑
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self. 阅读全文
posted @ 2020-05-09 15:04 星海寻梦233 阅读(96) 评论(0) 推荐(0) 编辑
摘要: class Solution: def generate(self, numRows: int) -> List[List[int]]: if numRows == 0: return None if numRows == 1: return [[1]] ans = [[1]] for j in r 阅读全文
posted @ 2020-05-09 15:03 星海寻梦233 阅读(100) 评论(0) 推荐(0) 编辑
摘要: class Solution: def maxProfit(self, prices: List[int]) -> int: length = len(prices) if length == 0: return 0 minBuyPrice = prices[0] maxProfit = 0 for 阅读全文
posted @ 2020-05-09 15:01 星海寻梦233 阅读(97) 评论(0) 推荐(0) 编辑
摘要: class Solution: def singleNumber(self, nums: List[int]) -> int: a = 0 for i in range(len(nums)): a = a^nums[i] return a 阅读全文
posted @ 2020-05-09 14:58 星海寻梦233 阅读(79) 评论(0) 推荐(0) 编辑
摘要: class MinStack: def __init__(self): """ initialize your data structure here. """ self.stack = [] def push(self, x: int) -> None: if len(self.stack) == 阅读全文
posted @ 2020-05-09 14:56 星海寻梦233 阅读(63) 评论(0) 推荐(0) 编辑
摘要: class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: lp = 0 rp = len(numbers) - 1 while lp < rp: if numbers[lp] + numbers[r 阅读全文
posted @ 2020-05-09 14:55 星海寻梦233 阅读(70) 评论(0) 推荐(0) 编辑
摘要: class Solution: def majorityElement(self, nums: List[int]) -> int: if len(nums) == 1: return nums[0] dic = {} n = len(nums) // 2 for i in range(len(nu 阅读全文
posted @ 2020-05-09 14:54 星海寻梦233 阅读(58) 评论(0) 推荐(0) 编辑
摘要: class Solution: def titleToNumber(self, s: str) -> int: ans = 0 for i in range(len(s)): ans = ans * 26 + ord(s[i])-64 return ans 阅读全文
posted @ 2020-05-09 14:52 星海寻梦233 阅读(111) 评论(0) 推荐(0) 编辑
摘要: class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ lenList = len(nums) w 阅读全文
posted @ 2020-05-09 14:51 星海寻梦233 阅读(75) 评论(0) 推荐(0) 编辑