自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(46)
  • 收藏
  • 关注

原创 Offer 33. 二叉搜索树的后序遍历序列

Offer 33. 二叉搜索树的后序遍历序列1. pythonclass Solution: def verifyPostorder(self, postorder: List[int]) -> bool: def recursion(i,j): if i>=j: return True p=i while postorder[p]<postorder[j]:

2021-04-01 10:04:02 123

原创 Offer 32 - III. 从上到下打印二叉树

Offer 32 - III. 从上到下打印二叉树1. pythonclass Solution: def levelOrder(self, root: TreeNode) -> List[List[int]]: if not root: return [] queue= collections.deque() queue.append(root) ret = [] while queu

2021-03-31 21:19:34 100

原创 Offer 32 - II. 从上到下打印二叉树

Offer 32 - II. 从上到下打印二叉树1. pythonclass Solution: def levelOrder(self, root: TreeNode) -> List[List[int]]: if not root: return [] queue = collections.deque() queue.append(root) ret=[] while queue:

2021-03-31 21:18:54 128

原创 Offer 32 - I. 从上到下打印二叉树

Offer 32 - I. 从上到下打印二叉树1. pythonclass Solution: def levelOrder(self, root: TreeNode) -> List[int]: if not root: return [] queue = collections.deque() queue.append(root) ret = [] while queue:

2021-03-31 21:17:45 98

原创 Offer 31. 栈的压入、弹出序列

Offer 31. 栈的压入、弹出序列1. pythonclass Solution: def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: stack ,i = [],0 for num in pushed: stack.append(num) while stack and stack[-1]==pop

2021-03-31 21:16:36 95

原创 Offer 28. 对称的二叉树

Offer 28. 对称的二叉树1. pythonclass Solution: def isSymmetric(self, root: TreeNode) -> bool: def recursion(l,r): if not l and not r: return True if not l or not r or r.val!=l.val: return F

2021-03-31 21:14:47 64

原创 Offer 26. 树的子结构

Offer 26. 树的子结构1. pythonclass Solution: def isSubStructure(self, A: TreeNode, B: TreeNode) -> bool: def recursion(A,B): if not B: return True if not A or not A.val==B.val: return Fals

2021-03-31 21:13:06 81

原创 Offer 25. 合并两个排序的链表

Offer 25. 合并两个排序的链表1. pythonclass Solution: def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: cur = tmpHead =ListNode(0) #此处注意, 指向同一个头节点 while (l1 and l2): if l1.val<l2.val: cur.next,l

2021-03-31 21:11:54 96

原创 Offer 21. 调整数组顺序使奇数位于偶数前面

Offer 21. 调整数组顺序使奇数位于偶数前面1. pythonclass Solution: def exchange(self, nums: List[int]) -> List[int]: queue =collections.deque() for num in nums: if num%2: queue.appendleft(num) else:

2021-03-31 21:10:12 62

原创 Offer 18. 删除链表的节点

Offer 18. 删除链表的节点1. pythonclass Solution: def deleteNode(self, head: ListNode, val: int) -> ListNode: pre,cur = head,head.next if val == pre.val: return head.next while cur and cur.val != val: pre =

2021-03-31 21:08:20 94

原创 14- II、 剪绳子(cuttingRope)

14- II、 剪绳子(cuttingRope)1. pythonclass Solution: def cuttingRope(self, n: int) -> int: if not n: return None dp=[0]*(n+1) dp[0]=0 dp[1]=dp[2]=1 for i in range(3,n+1): for j in range(i

2021-03-31 21:06:31 124

原创 Offer 54. 二叉搜索树的第k大节点(kthLargest)

Offer 54. 二叉搜索树的第k大节点(kthLargest)1. pythonclass Solution: def kthLargest(self, root: TreeNode, k: int) -> int: self.k = k def dfs(root): if not root: return 0 dfs(root.right) if s

2021-03-15 13:37:34 213

原创 Offer 53 - II. 0~n-1中缺失的数字(missingNumber)

Offer 53 - II. 0~n-1中缺失的数字(missingNumber)1. pythonclass Solution: def missingNumber(self, nums: List[int]) -> int: i,j = 0,len(nums)-1 while i<=j: mid =(i+j)//2 if nums[mid]==mid: i=mid+1

2021-03-15 13:17:15 97

原创 Offer 53 - I. 在排序数组中查找数字 I(search)

Offer 53 - I. 在排序数组中查找数字 I(search)1. pythonclass Solution: def search(self, nums: List[int], target: int) -> int: # cnt=0 # for v in nums: # if target ==v: # cnt+=1 # return cnt def helpe

2021-03-15 12:59:10 110

原创 Offer 15. 二进制中1的个数(hammingWeight)

Offer 15. 二进制中1的个数(hammingWeight)1. pythonclass Solution: def hammingWeight(self, n: int) -> int: cnt = 0 while n: cnt = cnt+1 n = n&(n-1) return cnt 2. Javapublic class Solution { //

2021-03-13 15:32:20 168

原创 Offer 12. 矩阵中的路径(exist)

Offer 12. 矩阵中的路径(exist)1. pythonclass Solution: def exist(self, board: List[List[str]], word: str) -> bool: def dfs(i,j,k): if not 0<=i<len(board) or not 0<=j<len(board[0]) or not board[i][j]== word[k]:

2021-03-13 10:38:17 122

原创 Offer 11. 旋转数组的最小数字(minArray)

Offer 11. 旋转数组的最小数字(minArray)1. pythonclass Solution: def minArray(self, numbers: List[int]) -> int: length = len(numbers) for i in range(1,length): if numbers[i]<numbers[i-1]: return numbers[i]

2021-03-13 10:06:24 255

原创 10- II. 青蛙跳台阶问题(numWays)

Offer 10- II. 青蛙跳台阶问题(numWays)1. pythonclass Solution: def numWays(self, n: int) -> int: a,b = 1,1 for _ in range(n): a ,b = b,a+b return a % 1000000007 2. Javaclass Solution { public int numWays

2021-03-12 15:32:17 179

原创 09. 用两个栈实现队列(CQueue)

09. 用两个栈实现队列(CQueue)1. pythonclass CQueue: def __init__(self): self.A = [] self.B = [] def appendTail(self, value: int) -> None: self.A.append(value) def deleteHead(self) -> int: if self.B:

2021-03-12 13:53:49 120

原创 34. 二叉树中和为某一值的路径(pathSum)

34. 二叉树中和为某一值的路径(pathSum)1. pythonclass Solution: def __init__(self): self.ret,self.path=[],[] def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: if not root: return[] self.path.append(root.val)

2021-03-09 11:03:03 107

原创 9. 回文数(twoSum)

9. 回文数(twoSum)1. pythonclass Solution: def isPalindrome(self, x: int) -> bool: if x<0 or (x!=0 and x%10==0): return False reversedNumber=0 while x>reversedNumber: reversedNumber = reversedNumbe

2021-03-05 20:48:39 66

原创 7. 重建二叉树(buildTree)

7. 重建二叉树(buildTree)1. pythonclass Solution: def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode: if not preorder and not inorder: return None root =TreeNode(preorder[0]) inorderIndex=inorder

2021-02-08 21:09:27 464

原创 68 - II. 二叉树的最近公共祖先(lowestCommonAncestor)

68 - II. 二叉树的最近公共祖先(lowestCommonAncestor)1. pythonclass Solution: def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode: if not root or p==root or q == root: return root left = self.lowest

2021-01-25 12:58:25 104

原创 68 - I. 二叉搜索树的最近公共祖先(lowestCommonAncestor)

68 - I. 二叉搜索树的最近公共祖先(lowestCommonAncestor)1. pythonclass Solution: def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': if not root or root ==p or root ==q: return root left = se

2021-01-25 12:49:41 80

原创 57. 和为s的两个数字(twoSum)

57. 和为s的两个数字(twoSum)1. pythonclass Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: i,j = 0,len(nums)-1 while i<j: sum = nums[i]+nums[j] if sum >target: j-=1

2021-01-25 11:56:40 130 1

原创 63. 股票的最大利润( maxProfit)

63. 股票的最大利润( maxProfit)1. python(1)class Solution: def maxProfit(self, prices: List[int]) -> int: if not prices: return 0 length = len(prices) minPrice = prices[0] dp = length*[0] for i in range(

2021-01-24 19:38:10 568

原创 52. 两个链表的第一个公共节点 ( ListNode getIntersectionNode)

52. 两个链表的第一个公共节点 ( ListNode getIntersectionNode)1. pythonclass Solution: def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: node1,node2 = headA,headB while node1!=node2: node1=node1.next if nod

2021-01-24 10:51:35 198

原创 47. 礼物的最大价值 ( maxValue)

47. 礼物的最大价值 ( maxValue)1. pythonclass Solution: def maxValue(self, grid: List[List[int]]) -> int: row ,col= len(grid),len(grid[0]) for j in range(1,col): #初始化第一行 grid[0][j]+=grid[0][j-1] for i in range(1,row):

2021-01-23 15:02:56 278

原创 6. 从尾到头打印链表 ( reversePrint)

6. 从尾到头打印链表 ( reversePrint)1. python(1)class Solution: def reversePrint(self, head: ListNode) -> List[int]: stack = [] while head: stack.append(head.val) head = head.next stack.reverse() retu

2021-01-22 16:31:41 2082

原创 5. 替换空格 (replaceSpace)

5. 替换空格 (replaceSpace)1. python(1)class Solution: def replaceSpace(self, s: str) -> str: lst=[] for c in s: if c == " ":lst.append("%20") else: lst.append(c) return "".join(lst)2. Javaclass Solut

2021-01-22 16:07:05 843

原创 4. 二维数组中的查找 (findNumberIn2DArray)

4. 二维数组中的查找 (findNumberIn2DArray)1. python(1)class Solution: def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -> bool: i,j = len(matrix)-1,0 while i>=0 and j<len(matrix[0]): if matrix[i][j]<

2021-01-22 15:54:29 476

原创 3. 数组中重复的数字 (findRepeatNumber)

3. 数组中重复的数字 (findRepeatNumber)1. python(1)class Solution: def findRepeatNumber(self, nums: List[int]) -> int: sorted_nums = sorted(nums) sorted_nums_length = len(sorted_nums) for i in range(sorted_nums_length):

2021-01-22 15:35:25 563

原创 MySQL(predicate)

表常常被认为是行的集合,但从谓词逻辑的观 点看,也可以认为是命题的集合(=陈述句的集合)1. MySQL谓词定义谓词是一种特殊的函数,返回值是真值。前面提到的每个谓词,返回值都是 true、 false 或者 unknown(一般的谓词逻辑里没有unknown,但是 SQL 采用的是三值逻辑,因此具有三种真值)。2. MySQL谓词分类及比较3. MySQL谓词的阶层EXISTS 因接受的参数是集合这样的一阶实体而被称为二阶谓词。(高阶函数)零阶谓词=一阶谓词= 等输入值为一行

2021-01-12 15:34:39 679 1

原创 MySQL(DDL,DML,DCL)

MySQL1969 年 Codd 在 开 始思考关系模型时曾强调过,数据库(和名字无关)实际上并非是数据的集合,而是事实(即真命题)的集合。(”Database in Depth:Relational Theory for Practitioners,O’Reilly Media,2005)1. DDL(data definition language)1.建表DROP TABLE IF EXISTS T_DEMO;CREATE TABLE t_demo(uid int(10) PRI

2021-01-12 15:03:07 130

原创 946. 验证栈序列(validateStackSequences)

946. 验证栈序列(validateStackSequences)1. pythonclass Solution: def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: stack,i=[],0 for num in pushed: stack.append(num) while stack and st

2021-01-09 18:44:16 141

原创 31. 栈的压入、弹出序列(validateStackSequences)

31. 栈的压入、弹出序列(validateStackSequences)1. pythonclass Solution: def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: stack,i =[],0 for num in pushed: stack.append(num) while stack an

2021-01-09 18:42:25 111

原创 29. 顺时针打印矩阵(spiralOrder)

29. 顺时针打印矩阵(spiralOrder)1. pythonclass Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: if not matrix: return [] left,top=0,0; right=len(matrix[0]) bottom=len(matrix) ans=[]

2021-01-09 15:07:12 147

原创 54. 螺旋矩阵(spiralOrder)

54. 螺旋矩阵(spiralOrder)1. pythonclass Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: if not matrix:return [] left,top=0,0 right,bottom=len(matrix[0]),len(matrix) ans=[] while left<ri

2021-01-09 15:04:27 393

原创 3.无重复最长字串(lengthOfLongestSubstring)

3. 无重复最长字串(lengthOfLongestSubstring)1. pythonclass Solution: def lengthOfLongestSubstring(self, s: str) -> int: if not s: return 0 cur_len,max_len=0,0 s_len = len(s) left = 0 hashSet = set()

2021-01-08 16:59:09 433

原创 2. 两数相加addTwoNumbers

2. 两数相加addTwoNumbers(twoSum)1. pythonclass Solution: def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: carry = 0 pre=ListNode(0); cur=pre while(l1 or l2): x=0 if l1==None else l1.val

2021-01-08 13:43:01 99

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除