散列
摘要:散列概念 散列是一种用于常数平均时间执行插入、删除和查找的技术。理想的散列表数据结构不过是一个包含关键字的具有固定大小的数组。数组的每个位置存储一条信息,并且与一个唯一的关键字有确定的映射关系f,f被称为散列函数。这样在已知关键字k和散列函数f时,就能 唯一确定存储的信息。理想情况下,存储信息的位置
阅读全文
二叉树总结(四)平衡二叉树
摘要:平衡二叉树概念 AVL树是根据它的发明者G.M. Adelson-Velsky和E.M. Landis命名的。它是最先发明的自平衡二叉查找树,也被称为高度平衡树。相比于"二叉查找树",它的特点是:AVL树中任何节点的两个子树的高度最大差别为1。 AVL树的查找、插入和删除在平均和最坏情况下都是O(l
阅读全文
二叉树总结(三)二叉搜索树
摘要:二叉搜索树 对于二叉树,假设x为二叉树中的任意一个结点,x节点包含关键字key,节点x的key值记为key[x]。如果y是x的左子树中的一个结点,则key[y] <= key[x];如果y是x的右子树的一个结点,则key[y] >= key[x]。那么,这棵树就是二叉查找树。 性质 若任意节点的左子
阅读全文
[LeetCode]Construct Binary Tree from Preorder and Inorder Traversal
摘要:105. Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may
阅读全文
二叉树总结(一)概念和性质
摘要:一、树的概念 树是一些点的集合,这个集合可以为空,若不为空,则它是由一个根节点和0个或多个为空的子树组成,且每个子树都被一条来自根节点的有向边相连。 树叶:没有儿子的节点;兄弟:具有相同父亲的节点;类似还有祖父和孙子节点。 路径:节点n1,n2,n3,...,nk的一个序列,使得对于1 <= i <
阅读全文
栈和队列
摘要:栈和队列都属于限制了插入、删除操作的表。栈要求插入、删除操作都只能作用在一端;队列要求插入、删除操作不能作用在同一端。 因此,栈是先进后出的一种数据结构,队列是先进先出的数据结构。 C++的标准库中有栈模板,它的详细操作介绍请参考这篇博文:http://www.cnblogs.com/yeqluof
阅读全文
[LeetCode]Copy List with Random Pointer
摘要:题目:Copy List with Random Pointer A linked list is given such that each node contains an additional random pointer which could point to any node in the
阅读全文
线性表
摘要:线性表定义 线性表:由零个或多个数据元素组成的有限序列。 注意: 1.线性表是一个序列。 2.0个元素构成的线性表是空表。 3.线性表中的第一个元素无前驱,最后一个元素无后继,其他元素有且只有一个前驱和后继。 4.线性表是有长度的,其长度就是元素个数,且线性表的元素个数是有限的,也就是说,线性表的长
阅读全文
[LeetCode]Top K Frequent Elements
摘要:题目:Top K Frequent Elements Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2,2,3] and k = 2, return
阅读全文
[LeetCode]Reverse String
摘要:题目:Reverse String Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 题意:逆置字符串 思
阅读全文
[LeetCode]Integer Break
摘要:题目:Integer Break Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Retur
阅读全文
[LeetCode]Power of N
摘要:题目:Power of Two Given an integer, write a function to determine if it is a power of two. 题意:判断一个数是否是2的k次方数。 思路: 2的次方数使用2进制表示则必然只有最高位是1其他都是0; 这样判断一个数最多
阅读全文
[LeetCode]Palindrome Pairs
摘要:题目:Palindrome Pairs Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two wo
阅读全文
[LeetCode]Gray Code
摘要:题目:Gray Code 给定格雷码的位数,输出所有的格雷码对应的十进制数。 思路: 000 0 001 1 011 3 010 2 110 6 111 7 101 5 100 4 前四个和后四个的前两位对称,前两个和后两个的第一位是对称的。 如此,可看出,格雷码有一定的对称性。
阅读全文
C++基础之动态内存
摘要:C++支持动态分配对象,它的生命周期与它们在哪里创建无关,只有当显示的被释放时,这些对象才会被销毁。分配在静态或栈内存中的对象由编译器自动创建和销毁。 new在动态内存中为对象分配空间并返回一个指向该对象的指针,并调用构造函数构造对象;delete接受一个动态对象指针,调用析构函数销毁该对象,并释放
阅读全文
Trie树
摘要:什么是Trie树? Trie树,又叫字典树、前缀树(Prefix Tree)、基数树(radix tree)、单词查找树 或 键树,是一种多叉树结构。它是一种搜索树,具有有序的树结构,用来存储数据集或关联阵列,其中键通常是字符串。与二叉树不同,它节点上并没有存key,但是它定义了与key相关联的位置
阅读全文
[LeetCode]The Skyline Problem
摘要:题目:The Skyline Problem A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. N
阅读全文
[LeetCode]Implement Trie (Prefix Tree)
摘要:题目:Implement Trie (Prefix Tree) 实现字典树。 什么是字典树? Trie树,又叫字典树、前缀树(Prefix Tree)、单词查找树 或 键树,是一种多叉树结构。如下图: 上图是一棵Trie树,表示了关键字集合{“a”, “to”, “tea”, “ted”, “ten
阅读全文
C++基础之适配器
摘要:什么是容器适配器? ”适配器是使一种事物的行为类似于另外一种事物行为的一种机制”,适配器对容器进行包装,使其表现出另外一种行为。例如,stack<int, vector<int> >实现了栈的功能,但其内部使用顺序容器vector<int>来存储数据。(相当于是vector<int>表现出了栈的行为
阅读全文
[LeetCode]Self Crossing
摘要:题目:Self Crossing You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the
阅读全文