01 2015 档案
摘要:地址解析协议(Address Resolution Protoclol),其基本功能为通过目标设备的IP地址,查询目标设备的MAC地址,以保证通信的顺利。它是IPV4中网络层必不可少的协议。不过在IPV6中已经不再适用,并被邻居发现协议(NDP)所代替。 当一台主机把以太网数据帧发送到位于同一...
阅读全文
摘要:一、什么是分治 有很多算法是递归的:为了解决一个给定的问题,算法要一次或多次递归调用其自身来解决的子问题。这些算法通常采用分治策略:将原问题划分为n个规模较小而结构与原问题相似的子问题;递归地解决这些子问题,然后再合并其结果,就得到原问题的解。 习惯上,在正文中至少含有两个递归调用的例程叫作...
阅读全文
摘要:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ...
阅读全文
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:递归的思路。思路与重建二叉树类似。时间复杂度O(n), 空间复杂度O(logN) 1 /** 2 ...
阅读全文
摘要: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 n...
阅读全文
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ...
阅读全文
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an...
阅读全文
摘要:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution stil...
阅读全文
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe...
阅读全文
摘要:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 ...
阅读全文
摘要:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
阅读全文
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. 1 /** 2 * De...
阅读全文
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. 1 /** 2 * Def...
阅读全文
摘要:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al...
阅读全文
摘要:首先定义二叉树的存储结构: 1 struct TreeNode {2 int val;3 TreeNode *left;4 TreeNode *right;5 6 TreeNode(int v, TreeNode* l = NULL, TreeNode *r = N...
阅读全文
摘要:iven a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exam...
阅读全文
摘要:Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
阅读全文
摘要:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note...
阅读全文
摘要:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No...
阅读全文
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not...
阅读全文
摘要:平衡树是计算机科学中的一类数据结构。平衡树是计算机科学中的一类改进的二叉查找树。一般的二叉查找树的查询复杂度是跟目标结点到树根的距离(即深度)有关,因此当结点的深度普遍较大时,查询的均摊复杂度会上升,为了更高效的查询,平衡树应运而生了。 在这里,平衡指所有叶子的深度趋于平衡,更广义的是指在树上...
阅读全文
摘要:二叉搜索树,也叫二叉排序树、二叉查找树或BST(Binary Search Tree)。二叉搜索树或是一棵空疏,或者是一棵具有下列特性的非空二叉树:1. 若左子树非空,则左子树上的所有节点的关键字值均小于根节点的关键字的值。2. 若右子树非空,则右子树上的所有节点的关键字值均大于根节点的关键字的值。...
阅读全文
摘要:二叉树的存储结构: 1 struct BinaryTreeNode {2 int val;3 BinaryTreeNode *left;4 BinaryTreeNode *right;5 6 BinaryTreeNode(in...
阅读全文
摘要:C++支持另一个关键字struct,它也可以定义类类型。struct关键字是从C语言继承过来的。默认初始访问级别不同: 如果使用class关键字来定义类,那么定义在第一个访问标号前的任何成员都隐式指定为private;如果使用struct关键字,那么这些成员都是public,使用class还是...
阅读全文
摘要:在函数返回类型前加上关键字inline就可以将函数指定为内联函数:1 inline const string& shortString(const string &s1, const string &s2) {2 return s1.size() < s2.size() ? s1 : s2;...
阅读全文
摘要:函数重载: 出现在相同作用域中的两个函数,如果具有相同的名字而形参表不同,则称为重载函数(overloaded function)。一定要注意函数重载的两个关键词:形参列表和作用域。 任何程序有且仅有一个main函数的实例,main函数不能重载。 对于函数重载来说,它们应该在形参数量和形参类型...
阅读全文
摘要:优先队列的实现 优先队列是拥有权值观念的队列,它允许加入新元素,移除旧元素、审视元素值等功能。由于这是一个queue,所以只允许在底端加入元素,并从顶端取出元素,除此之外无其他存取元素的途径。 优先队列带有权值观念,其内的元素并非按照被推入的次序排列,而是自动依照元素的权值排列(通常权值以实值表...
阅读全文
浙公网安备 33010602011771号