[LeetCode]449. Serialize and Deserialize BST 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/serialize-and-deserialize-bst/description/ 题目描述: Serialization is the process of converting a data structure or object into a sequence of bits s…
题目如下: Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another…
[LeetCode]297. Serialize and Deserialize Binary Tree 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/serialize-and-deserialize-binary-tree/description/ 题目描述: Serialization is the process of converting a data structure or object into a se…
二叉树的序列化与反序列化. 如果使用string作为媒介来存储,传递序列化结果的话,会给反序列话带来很多不方便. 这里学会了使用 sstream 中的 输入流'istringstream' 和 输出流'ostringstream'. istringstream in; in >> str; 这里没执行一次就会倒出一个string (因为in流中使用了' '空格 作为分割符, 所以可以分成很多个string) 建树的时候使用先序建立二叉树. 关键代码如下: TreeNode* build(ist…
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comput…
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comput…
原题链接在这里:https://leetcode.com/problems/serialize-and-deserialize-bst/description/ 题目: Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted acr…
https://leetcode.com/problems/serialize-and-deserialize-bst/#/description Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a netwo…
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comput…
这道题学到了东西. /* 一开始想着中序遍历,但是解码的时候才发现,中序遍历并不能唯一得确定二叉树. 后来看了网上的答案,发现先序遍历是可以的,观察了一下,对于BST,先序遍历确实是可以 唯一得确定. 对于一般的二叉树,必须是前序和中序或者后序和中序才能唯一确定,其中中序的作用就是 确定中心位置,以确定左右子树的前序(后序)的范围 但是对于BST根据性质,左子树的前序序列最大的就是1st节点,所以找到序列中第一个比 1st节点大的节点就是右子树的开始,这样就不需要中序了 还有一种方法,保存二叉树…
详见:https://leetcode.com/problems/serialize-and-deserialize-bst/description/ C++: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode.com/contest/weekly-contest-110/problems/range-sum-of-bst/ 题目描述 Given the root node of a binary search tree, return the sum of values of all nodes wi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 中序遍历 日期 题目地址:https://leetcode.com/problems/minimum-distance-between-bst-nodes/description/ 题目描述 Given a Binary Search Tree (BST) with the root node root, return the minimum dif…
[94]Binary Tree Inorder Traversal [95]Unique Binary Search Trees II (2018年11月14日,算法群) 给了一个 n,返回结点是 1 - n 的所有形态的BST. 题解:枚举每个根节点 r, 然后递归的生成左右子树的所有集合,然后做笛卡尔积. /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * Tr…
链接:https://leetcode.com/tag/binary-search-tree/ [220]Contains Duplicate III (2019年4月20日) (好题) Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[…
[LeetCode]729. My Calendar I 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/my-calendar-i/description/ 题目描述: Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.…
[LeetCode]385. Mini Parser 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/mini-parser/description/ 题目描述: Given a nested list of integers represented as a string, implement a parser to deserialize it. Each element is either an integer, o…
[LeetCode]331. Verify Preorder Serialization of a Binary Tree 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/description/ 题目描述: One way to serialize a binary tree is to use pre-order traver…
[LeetCode]109. Convert Sorted List to Binary Search Tree 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/description/ 题目描述: Given a s…
[LeetCode]95. Unique Binary Search Trees II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/unique-binary-search-trees-ii/description/ 题目描述: Given an integer n, generate all s…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/description/ 题目描述 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in…
[LeetCode]99. Recover Binary Search Tree 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/recover-binary-search-tree/description/ 题目描述: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without chan…
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 递归和非递归,此提比较简单.广度优先遍历即可.关键之处就在于如何保持访问深度. 下面是4种代码: im…
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 思路:最简单的方法就是依照[Leetcode]Pascal's Triangle 的方式自顶向下依次求解,但会造成空间的浪费.若仅仅用一个vect…
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the largest sum = 6. 挑…
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. The order of elements can b…
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位数字.在这样做的时候,我们可以预先检查向原整数附加另一位数字是否会导致溢出. 算法: 反转整数的方法可以与反转字符串进行类比. 我们想重复"弹出" x 的最后一位数字,并将它"推入"到 rev 的后面.最后,rev 将与 x 相反. 要在没有辅助堆栈 / 数组的帮助下…
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法…
Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-of-special-equivalent-strings/ 1)problem You are given an array A of strings. Two strings S and T are special-equivalent if after any number of moves,…
Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin/ 1)problem There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0,…