摘要: 题目: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 @ 2014-05-14 17:20 ThreeMonkey 阅读(165) 评论(0) 推荐(0)
摘要: 题目: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,... 阅读全文
posted @ 2014-05-14 17:13 ThreeMonkey 阅读(148) 评论(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 and... 阅读全文
posted @ 2014-05-14 17:11 ThreeMonkey 阅读(174) 评论(0) 推荐(0)
摘要: 题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest... 阅读全文
posted @ 2014-05-14 17:09 ThreeMonkey 阅读(143) 评论(0) 推荐(0)
摘要: 题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解题思路:前序遍历序列的... 阅读全文
posted @ 2014-05-14 17:07 ThreeMonkey 阅读(174) 评论(0) 推荐(0)
摘要: 题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解题思路:后序遍历的最... 阅读全文
posted @ 2014-05-14 17:05 ThreeMonkey 阅读(141) 评论(0) 推荐(0)
摘要: 题目:Given 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 ... 阅读全文
posted @ 2014-05-14 16:59 ThreeMonkey 阅读(151) 评论(0) 推荐(0)
摘要: 题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:同链表的方法一样。一分为二,递归进行求解。代码: 1 /** 2 * Definitio... 阅读全文
posted @ 2014-05-14 16:49 ThreeMonkey 阅读(136) 评论(0) 推荐(0)
摘要: 题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:注意是让构造平衡二叉搜索树。每次将链表从中间断开,分成左右两部分。... 阅读全文
posted @ 2014-05-14 16:46 ThreeMonkey 阅读(133) 评论(0) 推荐(0)
摘要: 题目: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 de... 阅读全文
posted @ 2014-05-14 16:42 ThreeMonkey 阅读(118) 评论(0) 推荐(0)
摘要: 题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest... 阅读全文
posted @ 2014-05-14 16:25 ThreeMonkey 阅读(139) 评论(0) 推荐(0)
摘要: 题目:Given 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 the given sum... 阅读全文
posted @ 2014-05-14 16:22 ThreeMonkey 阅读(114) 评论(0) 推荐(0)
摘要: 题目:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsu... 阅读全文
posted @ 2014-05-14 16:18 ThreeMonkey 阅读(166) 评论(0) 推荐(0)
摘要: 题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattene... 阅读全文
posted @ 2014-05-14 16:15 ThreeMonkey 阅读(127) 评论(0) 推荐(0)
摘要: 题目:Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the o... 阅读全文
posted @ 2014-05-14 16:03 ThreeMonkey 阅读(153) 评论(0) 推荐(0)
摘要: 题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next poi... 阅读全文
posted @ 2014-05-14 15:54 ThreeMonkey 阅读(158) 评论(0) 推荐(0)
摘要: 题目: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 s... 阅读全文
posted @ 2014-05-14 15:52 ThreeMonkey 阅读(218) 评论(0) 推荐(0)
摘要: 题目:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4... 阅读全文
posted @ 2014-05-14 15:41 ThreeMonkey 阅读(120) 评论(0) 推荐(0)
摘要: 题目:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onl... 阅读全文
posted @ 2014-05-14 15:38 ThreeMonkey 阅读(105) 评论(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 @ 2014-05-14 15:34 ThreeMonkey 阅读(298) 评论(0) 推荐(0)
摘要: 题目:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction ... 阅读全文
posted @ 2014-05-14 15:25 ThreeMonkey 阅读(101) 评论(0) 推荐(0)
摘要: 题目:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complet... 阅读全文
posted @ 2014-05-14 15:22 ThreeMonkey 阅读(99) 评论(0) 推荐(0)
摘要: 题目:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complet... 阅读全文
posted @ 2014-05-14 15:19 ThreeMonkey 阅读(107) 评论(0) 推荐(0)
摘要: 题目: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 ... 阅读全文
posted @ 2014-05-14 15:16 ThreeMonkey 阅读(127) 评论(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 canal: P... 阅读全文
posted @ 2014-05-14 14:59 ThreeMonkey 阅读(124) 评论(0) 推荐(0)
摘要: 题目:Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can ... 阅读全文
posted @ 2014-05-14 11:34 ThreeMonkey 阅读(162) 评论(0) 推荐(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 longe... 阅读全文
posted @ 2014-05-14 11:25 ThreeMonkey 阅读(159) 评论(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 @ 2014-05-14 11:16 ThreeMonkey 阅读(106) 评论(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 surrounded reg... 阅读全文
posted @ 2014-05-14 11:07 ThreeMonkey 阅读(147) 评论(0) 推荐(0)
摘要: 题目:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, ... 阅读全文
posted @ 2014-05-14 10:59 ThreeMonkey 阅读(128) 评论(0) 推荐(0)
摘要: 题目:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ... 阅读全文
posted @ 2014-05-14 10:54 ThreeMonkey 阅读(140) 评论(0) 推荐(0)
摘要: 题目:Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled u... 阅读全文
posted @ 2014-05-14 10:45 ThreeMonkey 阅读(190) 评论(0) 推荐(0)
摘要: 题目:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costsco... 阅读全文
posted @ 2014-05-14 10:35 ThreeMonkey 阅读(115) 评论(0) 推荐(0)
摘要: 题目:There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following re... 阅读全文
posted @ 2014-05-14 10:31 ThreeMonkey 阅读(240) 评论(0) 推荐(0)
摘要: 题目: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime comple... 阅读全文
posted @ 2014-05-14 10:25 ThreeMonkey 阅读(101) 评论(0) 推荐(0)
摘要: 题目: Given an array of integers, every element appearsthreetimes except for one. Find that single one. Note: Your algorithm should have a linear run... 阅读全文
posted @ 2014-05-14 10:21 ThreeMonkey 阅读(146) 评论(0) 推荐(0)
摘要: 题目: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep ... 阅读全文
posted @ 2014-05-14 10:17 ThreeMonkey 阅读(122) 评论(0) 推荐(0)
摘要: 题目:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exa... 阅读全文
posted @ 2014-05-14 10:11 ThreeMonkey 阅读(204) 评论(0) 推荐(0)
摘要: 题目:Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such poss... 阅读全文
posted @ 2014-05-14 10:02 ThreeMonkey 阅读(201) 评论(0) 推荐(0)