![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode(python实现)
不服输的南瓜
这个作者很懒,什么都没留下…
展开
-
python --- LeetCode之 98. Validate Binary Search Tree
题目:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key.Th...原创 2019-06-08 16:04:03 · 286 阅读 · 0 评论 -
python --- LeetCode之 236. Lowest Common Ancestor of a Binary Tree
题目:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes...原创 2019-06-08 17:14:00 · 265 阅读 · 0 评论 -
python --- LeetCode之 235. Lowest Common Ancestor of a Binary Search Tree
题目:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwe...原创 2019-06-08 17:58:03 · 239 阅读 · 0 评论 -
python --LeetCode之102. Binary Tree Level Order Traversal
题目:Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).题目理解:可以使用广度优先搜索和深度优先搜索。方法一:广度优先搜索。利用队列,将每层的节点先存入队列,然后一个个取出来遍历每个节点的左右节点继续存入,...原创 2019-06-30 17:04:59 · 211 阅读 · 0 评论 -
300. 最长上升子序列
题目描述:给定一个无序的整数数组,找到其中最长上升子序列的长度。原创 2019-07-19 11:52:41 · 326 阅读 · 0 评论 -
382. 链表随机节点
题目描述:给定一个单链表,随机选择链表的一个节点,并返回相应的节点值。保证每个节点被选的概率一样。进阶:如果链表十分大且长度未知,如何解决这个问题?你能否使用常数级空间复杂度实现?思路:蓄水池抽样:(数学上可以证明,这里不做证明)从N个数中抽取k个数,N很大,k个数被抽中概率一样。方法:先初始化一个集合,集合中有k个元素,将此集合作为蓄水池。从第k+1个元素开始遍历,以概率是k...原创 2019-07-21 11:50:29 · 193 阅读 · 0 评论