本博客rss订阅地址: http://feed.cnblogs.com/blog/u/147990/rss
摘要: 其他LeetCode题目欢迎访问:LeetCode结题报告索引题目链接Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.N... 阅读全文
posted @ 2013-11-27 14:51 tenos 阅读(3322) 评论(2) 推荐(0) 编辑
摘要: 题目链接Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].... 阅读全文
posted @ 2013-11-27 13:21 tenos 阅读(1669) 评论(0) 推荐(0) 编辑
摘要: 题目链接Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.分析:首先要注意的是,输入数组中可能有重复的点。由于两点确定一条直线,一个很直观的解法是计算每两个... 阅读全文
posted @ 2013-11-26 20:45 tenos 阅读(10090) 评论(8) 推荐(3) 编辑
摘要: 其他LeetCode题目欢迎访问:LeetCode结题报告索引LeetCode:Word LadderGiven two words (startandend), and a dictionary, find the length of shortest transformation sequenc... 阅读全文
posted @ 2013-11-26 16:06 tenos 阅读(10693) 评论(5) 推荐(2) 编辑
摘要: 题目链接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 identica... 阅读全文
posted @ 2013-11-24 23:58 tenos 阅读(807) 评论(0) 推荐(0) 编辑
摘要: 题目链接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 /... 阅读全文
posted @ 2013-11-24 23:40 tenos 阅读(1329) 评论(0) 推荐(0) 编辑
摘要: LeetCode:Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You... 阅读全文
posted @ 2013-11-24 21:48 tenos 阅读(1483) 评论(2) 推荐(0) 编辑
摘要: LeetCode:Binary Tree Level Order TraversalGiven a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by ... 阅读全文
posted @ 2013-11-24 21:37 tenos 阅读(3349) 评论(0) 推荐(0) 编辑
摘要: 题目链接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 an... 阅读全文
posted @ 2013-11-24 21:21 tenos 阅读(999) 评论(0) 推荐(0) 编辑
摘要: LeetCode:Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST分析:... 阅读全文
posted @ 2013-11-24 15:30 tenos 阅读(1117) 评论(0) 推荐(1) 编辑
摘要: 题目链接Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the d... 阅读全文
posted @ 2013-11-24 15:21 tenos 阅读(609) 评论(0) 推荐(0) 编辑
摘要: LeetCode:Minimum Depth of Binary TreeGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from... 阅读全文
posted @ 2013-11-24 15:17 tenos 阅读(2950) 评论(2) 推荐(0) 编辑
摘要: LeetCode:Path SumGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals... 阅读全文
posted @ 2013-11-24 15:06 tenos 阅读(1755) 评论(0) 推荐(0) 编辑
摘要: 题目链接Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flatten... 阅读全文
posted @ 2013-11-24 14:57 tenos 阅读(574) 评论(0) 推荐(0) 编辑
摘要: 我的LeetCode解题报告索引题目链接Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is ... 阅读全文
posted @ 2013-11-24 14:50 tenos 阅读(2671) 评论(1) 推荐(1) 编辑
摘要: LeetCode:Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; ... 阅读全文
posted @ 2013-11-22 14:24 tenos 阅读(1002) 评论(0) 推荐(0) 编辑
摘要: LeetCode:Pascal's TriangleGivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1... 阅读全文
posted @ 2013-11-21 22:47 tenos 阅读(888) 评论(0) 推荐(0) 编辑
摘要: 题目链接Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the... 阅读全文
posted @ 2013-11-21 22:37 tenos 阅读(1747) 评论(0) 推荐(0) 编辑
摘要: LeetCode:Best Time to Buy and Sell StockSay you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted... 阅读全文
posted @ 2013-11-21 22:02 tenos 阅读(11564) 评论(5) 推荐(4) 编辑
摘要: 题目如下: 二叉树的最大路径和(题目链接)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 bin... 阅读全文
posted @ 2013-11-21 13:15 tenos 阅读(803) 评论(0) 推荐(0) 编辑
摘要: 最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考。根据我自己做的进度持续更新中...... 本文地址LeetCode:Reverse Words in a StringLeetCode:Evaluate Reverse Polish N... 阅读全文
posted @ 2013-11-20 23:09 tenos 阅读(9984) 评论(0) 推荐(0) 编辑
摘要: 题目如下:(题目链接)Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a ... 阅读全文
posted @ 2013-11-20 23:02 tenos 阅读(809) 评论(0) 推荐(0) 编辑
摘要: 题目如下:(题目链接)Sort a linked list inO(nlogn) time using constant space complexity.在上一题中使用了插入排序,时间复杂度为O(n^2)。nlogn的排序有快速排序、归并排序、堆排序。双向链表用快排比较适合,堆排序也可以用于链表,... 阅读全文
posted @ 2013-11-20 22:54 tenos 阅读(6354) 评论(4) 推荐(1) 编辑
摘要: 题目链接Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime comple... 阅读全文
posted @ 2013-11-13 22:34 tenos 阅读(474) 评论(0) 推荐(0) 编辑
摘要: 题目链接 链表的插入排序Sort a linked list using insertion sort.建议:为了操作方便,添加一个额外的头结点。代码如下: 本文地址 1 /** 2 * Def... 阅读全文
posted @ 2013-11-13 22:13 tenos 阅读(2697) 评论(1) 推荐(0) 编辑
摘要: 题目链接Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The long... 阅读全文
posted @ 2013-11-13 21:38 tenos 阅读(1059) 评论(0) 推荐(0) 编辑
摘要: 题目链接Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which... 阅读全文
posted @ 2013-11-13 16:44 tenos 阅读(670) 评论(0) 推荐(0) 编辑
摘要: 题目如下: (题目链接)Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surro... 阅读全文
posted @ 2013-11-13 15:46 tenos 阅读(785) 评论(0) 推荐(0) 编辑
摘要: LeetCode:Palindrome Partitioning题目如下:(把一个字符串划分成几个回文子串,枚举所有可能的划分)Given a strings, partitionssuch that every substring of the partition is a palindrome.... 阅读全文
posted @ 2013-11-13 13:56 tenos 阅读(1561) 评论(0) 推荐(0) 编辑
摘要: 题目如下:实现克隆图的算法 题目链接Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Node... 阅读全文
posted @ 2013-11-11 19:54 tenos 阅读(1473) 评论(0) 推荐(0) 编辑
摘要: 题目大意:设计一个用于LRU cache算法的数据结构。 题目链接。关于LRU的基本知识可参考here分析:为了保持cache的性能,使查找,插入,删除都有较高的性能,我们使用双向链表(std::list)和哈希表(std::unordered_map)作为cache的数据结构,因为:双向链表插入删... 阅读全文
posted @ 2013-11-10 22:19 tenos 阅读(7499) 评论(0) 推荐(0) 编辑
摘要: 题目(题目链接):Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values... 阅读全文
posted @ 2013-11-10 18:57 tenos 阅读(2797) 评论(0) 推荐(1) 编辑
摘要: 题目:非递归实现二叉树的后序遍历。题目链接算法1:非递归使用栈。首先把根节点压栈,然后循环如下操作:用一个变量来记录上次访问的节点,如果当前栈顶元素左右儿子都为空 或者 上次访问的节点非空且等于栈顶节点的左儿子或右儿子,则直接访问;否则把栈顶元素的右节点和左节点依次压栈。代码如下: 1 /** 2 ... 阅读全文
posted @ 2013-11-10 17:08 tenos 阅读(2065) 评论(0) 推荐(0) 编辑
摘要: 题目:非递归实现二叉树的前序遍历。题目链接算法1:使用栈的非递归遍历。先用根节点初始化栈,然后循环如下操作:访问栈顶节点,先后把栈顶节点右节点和左节点压栈(次序不能反,先右节点,后左节点),代码如下: 1 /** 2 * Definition for binary tree 3 * struct... 阅读全文
posted @ 2013-11-10 17:02 tenos 阅读(1941) 评论(0) 推荐(0) 编辑
摘要: 题目:判断单链表是否有环,如果有则找出环的起点。题目链接这是另一道题的扩展,利用快慢指针判断出是否有环后,还需要找出环的起点,分析如下:设链表长度为len(链表中非空next指针的个数,下面所说的长度均为非空next指针的个数),链表head到环的起点长度为a,环起点到快慢指针相遇点的长度为b,环的... 阅读全文
posted @ 2013-11-10 15:17 tenos 阅读(2039) 评论(0) 推荐(0) 编辑
摘要: 题目:判断单链表是否有环,要求O(1)空间复杂度。题目链接利用快慢指针,开始两个指针均指向链表head,然后循环移动,慢指针移动1步,快指针则移动2步,如果链表有环则两个指针一定会相遇。代码如下: 1 /** 2 * Definition for singly-linked list. 3 * ... 阅读全文
posted @ 2013-11-10 14:39 tenos 阅读(1293) 评论(0) 推荐(0) 编辑
摘要: pat 2-09 装箱问题模拟 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int findMatchBox(int tsize, vector &box) 7 { 8 for(int i = 0; i = tsize)return i;10 return -1;11 }12 13 int main()14 {15 int N;16 scanf("%d", &N);17 vector box;//box[i]为箱子i的剩余容量18 for(int i = 0; i 2... 阅读全文
posted @ 2013-11-07 18:57 tenos 阅读(832) 评论(0) 推荐(0) 编辑
摘要: google test 是google的c++开源单元测试工具,chrome的开发团队就是使用它。Code::Blocks 12.11(MinGW 4.7.1) (Windows版)Google Test 1.7.0一 编译Google Test运行cmake-gui在弹出来的对话框中Where is the source code之后填写解压的gtest,例如:D:/software/gtest-1.7.0Where to build the binaries之后填写生成的工程路径,例如:D:/software/gtest-1.7.0/codeblocks-mingw(网上看到说要点击Con 阅读全文
posted @ 2013-11-07 16:25 tenos 阅读(3327) 评论(1) 推荐(0) 编辑
摘要: 编程之美电子书下载24点游戏大家都知道:4张牌,可以进行+ - * / 四种运算,可以使用括号,每个牌用一次,任意组合构造表达式使结果为24。扩展问题:n个整数,四种运算,可使用括号,每个数字使用一次,使表达式结果为 k下面的算法1和算法2都是穷举,只是穷举的方式不一样,以下给出的两个算法代码都可以计算扩展问题。可能是集合操作原因,算法1的速度明显比算法2快书上分析如下 本文地址算法1:算法1代码如下,我在原来的基础上做了一点改动1、从数组中任选两个数时,保证数对前面没... 阅读全文
posted @ 2013-11-04 22:57 tenos 阅读(5217) 评论(2) 推荐(0) 编辑
摘要: pat1065 A+B and C 主要是注意一下加法溢出的情况,不要试图使用double,因为它的精度是15~16位,不能满足精度要求,代码如下: 1 #include 2 #include 3 #include 4 //double精度为15~16位,不能满足精度要求 5 int main() 6 { 7 int testNum; 8 scanf("%d",&testNum); 9 long long MAX = LONG_LONG_MAX; //pow(2,63) - 1,10 long long MIN = LONG... 阅读全文
posted @ 2013-11-04 16:05 tenos 阅读(1030) 评论(0) 推荐(0) 编辑

本博客rss订阅地址: http://feed.cnblogs.com/blog/u/147990/rss

公益页面-寻找遗失儿童