数据结构
夏天的风欧阳冰嫣
这个作者很懒,什么都没留下…
展开
-
刷题leetcode--532. K-diff Pairs in an Array
532. K-diff Pairs in an Array 2018.1.11Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer原创 2018-01-11 17:05:26 · 185 阅读 · 0 评论 -
JavaScript实现排序二叉树(数据结构)
被腾讯面试了2小时算法挂掉的前端不是好前端谁让前端JS那么火呢?SO 重新学习数据结构和算法吧!排序算法对前端来说非常重要!排序二叉树: 左子树小于根节点,右子树大于根节点,子树也满足这样的条件,这样的树叫做排序二叉树。所以JavaScript构建这样一个二叉树的过程如下:var BinaryTree = { var Node = function(){ }//定义二叉树的节点Node ...原创 2018-03-19 19:06:16 · 2242 阅读 · 0 评论 -
刷题leetcode_669. Trim a Binary Search Tree
二叉搜索树(binary search tree)定义二叉搜索树:二叉树中任何节点的键值一定大于其左子树中每一个节点的键值,并且小于其右子树中每一个节点的键值。查找基于此,在二叉搜索树中搜索最小元素和最大元素是方便的,从根节点开始,一直往左走,直至无路可走,就得到了最小元素;从跟节点开始,一直往右走,直至无路可走,就得到了最大元素。 查找任何一个节点原创 2018-01-09 21:47:20 · 149 阅读 · 0 评论 -
刷题leetcode--563. Binary Tree Tilt
2018.1.8路上的风景很精彩!享受过程!563. Binary Tree TiltGiven a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subt原创 2018-01-08 17:30:59 · 152 阅读 · 0 评论 -
刷题leetcode--654. Maximum Binary Tree
2018.1.8 15:47Fighting!Leetcode.654. Maximum Binary TreeGiven an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum numb原创 2018-01-08 15:22:53 · 195 阅读 · 0 评论 -
刷题leetcode--617. Merge Two Binary Trees
617. Merge Two Binary TreesGiven two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need原创 2018-01-08 13:50:52 · 163 阅读 · 0 评论 -
刷题leetcode102 Binary Tree Level Order Traversal
2018.1.7 FightingGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7]原创 2018-01-07 17:57:36 · 149 阅读 · 0 评论 -
刷题leetcode100 SameTree
2018.1.7加油!!Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the sam原创 2018-01-07 16:41:37 · 155 阅读 · 0 评论 -
刷题leetcode623 Add One Row to Tree
2018.1.7 10:42amGiven the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1.The adding rule is: giv原创 2018-01-07 10:21:28 · 245 阅读 · 0 评论 -
牛客网刷题——重建二叉树(剑指offer)
2018.1.6加油!题目描述输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回思路:递归方法,前序遍历第一个数字是根节点,在中序中找到其位置后可以划分出左右两个子树,再对子树进行递归,继续按上面原创 2018-01-06 10:42:43 · 331 阅读 · 0 评论 -
算法--递归
递归:注意两点:1.边界条件时( 有时有return,有时是别的操作)代码里用橘红色标出2.递归时参数变化(规模变小) 代码里用黄色标出 递归:你打开面前这扇门,看到屋里面还有一扇门(这门可能跟前面打开的门一样大小(静),也可能门小了些(动)),你走过去,发现手中的钥匙还可以打开它,你推开门,发现里面还有一扇门,你继续打开,。。。, 若干次之后,你打开面前一扇门,发原创 2018-01-06 09:53:18 · 263 阅读 · 0 评论 -
已知二叉树的中序和后序求前序
例子,后序遍历为 gbdehfca,中序遍历为 dgbaechf 后序遍历中的最后一个元素是根节点,a,然后查找中序中a的位置 把中序遍历分成 dgb a echf,而因为节点个数要对应 后序遍历分为 gbd ehfc a,gbd为左子树,ehfc为右子树,这样又可以递归计算了最后形成的二叉树如下图片所示:原创 2018-01-04 19:12:35 · 1305 阅读 · 0 评论 -
刷题leetcode--530. Minimum Absolute Difference in BST
530. Minimum Absolute Difference in BST2018.1.11Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input:原创 2018-01-11 15:22:31 · 249 阅读 · 0 评论 -
JS遍历DOM树—(二叉树算深度优先遍历特例)
目录:二叉 DOM 树的遍历:前序,中序,后序多叉 DOM 树的遍历:广度优先搜索(队列),深度优先搜索(栈)二叉 DOM 树的前序、中序、后序遍历,是深度优先遍历的特例二叉 DOM 树的遍历[javascript] view plain copyfunction Tree() { var Node = function(key){ this...原创 2018-03-23 17:15:53 · 922 阅读 · 0 评论