摘要: 题目描述; 方法一:O(N) O(1) # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: 阅读全文
posted @ 2019-10-05 19:06 oldby 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:双栈 class MyQueue: def __init__(self): """ Initialize your data structure here. """ from collections import deque self.stack = deque() def pu 阅读全文
posted @ 2019-10-05 18:47 oldby 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交: class Solution: def isPowerOfTwo(self, n: int) -> bool: if n==0:return False if n==1: return True s = str(bin(n))[3:] for i in s: if i == 阅读全文
posted @ 2019-10-05 16:40 oldby 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:递归: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None cl 阅读全文
posted @ 2019-10-05 16:16 oldby 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:摩尔投票法 class Solution: def majorityElement(self, nums: List[int]) -> List[int]: candiate1 = candiate2 = None cnt1 = cnt2 = 0 for num in nums: 阅读全文
posted @ 2019-10-05 14:28 oldby 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 第一次提交:双指针 O(N) class Solution: def summaryRanges(self, nums: List[int]) -> List[str]: #first = 0 last = 0 res = [] while last!=len(nums): first 阅读全文
posted @ 2019-10-05 11:33 oldby 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 方法一:中缀转后缀 #!_*_coding:utf-8_*_ class Solution: def calculate(self, s: str) -> int: def in_to_suffix(s): priority = {'+': 1, '-': 1, '*': 2, '/': 阅读全文
posted @ 2019-10-05 11:03 oldby 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 题目描述: from collections import deque class MyStack: def __init__(self): """ Initialize your data structure here. """ self.queue = deque() def push(self 阅读全文
posted @ 2019-10-05 09:32 oldby 阅读(218) 评论(0) 推荐(0) 编辑