01 2016 档案
摘要:之前刷题的时候,很多类似二叉树的题,但是千变万化,基本上都是几种遍历,反转,求高度这些的变形或者组合,所以这里索性直接写一个得了: 首先是二叉树的节点:1 template2 struct TreeNode{3 T val;4 TreeNode * left;5 Tre...
阅读全文
摘要:现在可能STL使用的越来越多,但是一些较老的api并不支持例如vector这样的兑现,但是可以使用一些技巧来使其适应于这些函数。 例如对于使用到int*型的函数来说,传入一个 &vector[1],是完全可以的,再比如说C语言经常使用到的memcpy,下面的使用也是可以的:1 vector n...
阅读全文
摘要:图常用的存储方法又邻接表表示法以及邻接矩阵表示法,邻接表适合稀疏矩阵的存储,但是缺点是稍微复杂一点,并且插入操作或者说更新图的操作实际上是比较复杂的,而邻接矩阵更加简单,再存储密集矩阵的时候更加合适,下面使用c++实现一个简单的邻接矩阵。 由于图一般简单的分为几种:1. 无向图 2.有向图 3...
阅读全文
摘要:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to...
阅读全文
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-...
阅读全文
摘要:Implement a trie withinsert,search, andstartsWithmethods.实现字典树,前面好像有道题做过类似的东西,代码如下: 1 class TrieNode { 2 public: 3 // Initialize your data structu...
阅读全文
摘要:Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]. 看起来感觉不像har
阅读全文
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.由于对于这个二叉搜索树的要求是其必须是其必须是平衡的,所以应该使用递归。首先找到二...
阅读全文
摘要:Given an Iterator class interface with methods:next()andhasNext(), design and implement a PeekingIterator that support thepeek()operation -- it essent...
阅读全文
摘要:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two...
阅读全文
摘要:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top()...
阅读全文
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value t...
阅读全文
摘要:比较典型的一个题目,easy,不过可以有许多实现方式。这里用的方式是每次pop完成之后再将stack2中的内容立即倒回stack1中。但是其他的实现也可以不是这样,可以是需要push的时候检查再,如果内容在stack2中,这时候将其倒回在进行push。这里采取第一种比较笨的方法,代码如下所示: 1 ...
阅读全文
摘要:Given apatternand a stringstr, find ifstrfollows the same pattern.Herefollowmeans a full match, such that there is a bijection between a letter inpatt...
阅读全文
摘要:在做表达式处理的时候,逆波兰表示法还是很有用的。比如说一个式子(A+B)*C+D-(E-F)这样一个式子可以简单的用逆波兰表示法表示成:AB+C*D+EF--,这样就去掉了表达式中的所有的括号。一个表达式的逻辑处理也更简单了,下面会举一个例子,先占一个坑。
阅读全文

浙公网安备 33010602011771号