随笔分类 - leetcode
leetcode刷题记录
摘要:不是我自己做出来的 class Solution(object): def generateTrees(self,n): Listn = [i for i in range(1, n+1)] def gt(List): res = [] if not List: return [None] if l
阅读全文
摘要:class Solution(object): def isSymmetric(self, root): """ :type root: TreeNode :rtype: bool """ if not root:return True def Tree(p,q): if not p and not
阅读全文
摘要:超出时间了。。。 class Solution(object): def countRangeSum(self, nums, lower, upper): """ :type nums: List[int] :type lower: int :type upper: int :rtype: int
阅读全文
摘要:也不是我做出来的,, class Solution(object): def isValidBST(self, root): """ :type root: TreeNode :rtype: bool """ res=[] def helper(root): if not root: return
阅读全文
摘要:这不是我写的,对于树的学习处于初始阶段。 class Solution(object): def inorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ white,gray=0,1 res=[] st
阅读全文
摘要:class Solution(object): def removeKdigits(self, num, k): """ :type num: str :type k: int :rtype: str """ if k>=len(num): return '0' i=0 j=1 while k an
阅读全文
摘要:这道题也不是我自己做出来的,只能说大佬牛逼!!! class Solution(object): def decodeString(self, s): """ :type s: str :rtype: str """ stack, res, multi = [], "", 0 for c in s:
阅读全文
摘要:这个也不是我自己做出来的,感觉我还打不到这个水平,我好菜! class Solution: def maximalRectangle(self, matrix) -> int: if not matrix or not matrix[0]: return 0 row = len(matrix) co
阅读全文
摘要:class Solution(object): def largestRectangleArea(self, heights): """ :type heights: List[int] :rtype: int """ stack = [] heights = [0] + heights + [0]
阅读全文
摘要:class Solution(object): def simplifyPath(self, path): """ :type path: str :rtype: str """ stack=[] path=path.split('/') for item in path: if item=='..
阅读全文
摘要:# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def
阅读全文
摘要:用栈做: # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object):
阅读全文
摘要:# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def
阅读全文
摘要:慢慢找到对链表的感觉,加油保持前进呀哈哈哈哈!!!! # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None c
阅读全文
摘要:class Solution(object): def rotateRight(self, head, k): """ :type head: ListNode :type k: int :rtype: ListNode """ if not head: return if head.next==N
阅读全文
摘要:借助新增加的结点 class Solution(object): def swapPairs(self, head): """ :type head: ListNode :rtype: ListNode """ if not head: return if head.next==None: retu
阅读全文
摘要:class Solution: def countAndSay(self, n: int) -> str: r={} r[1]='1' r[2]='11' r[3]='21' r[4]='1211' r[5]='111221' if n in r: return r[n] else: i=6 whi
阅读全文
摘要:用列表完成!!!! # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def remove
阅读全文
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def mergeTwoLists(se
阅读全文
摘要:第一次解除到链表相关的题目,不会做,看了别人答案。 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solu
阅读全文

浙公网安备 33010602011771号