上一页 1 2 3 4 5 6 7 8 ··· 10 下一页

2014年2月11日

摘要: 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 to search. If found in the array return its inde... 阅读全文
posted @ 2014-02-11 11:18 小唯THU 阅读(194) 评论(0) 推荐(0) 编辑

2014年2月7日

摘要: 【InorderTraversal】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:Recursive solution is trivial, could you do it iteratively?confused what"{1,#,2,3}"means?> read more on how binary tree is seria 阅读全文
posted @ 2014-02-07 23:14 小唯THU 阅读(349) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文
posted @ 2014-02-07 01:35 小唯THU 阅读(454) 评论(0) 推荐(0) 编辑

2014年2月6日

摘要: 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,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its level order traversal as:[ [3], [9,20], [15,7]]confused what"{1,#,2,3}"means?> read more . 阅读全文
posted @ 2014-02-06 23:41 小唯THU 阅读(243) 评论(0) 推荐(0) 编辑
摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2014-02-06 18:47 小唯THU 阅读(286) 评论(0) 推荐(0) 编辑
摘要: You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:每次转着圈挪四个元素,这步只需要一个int的额外空间,想象一个方阵哦不好意思,这个太不专业了,咱换个大一点6×6的草图上比划比划第二层的元素怎么移动,一次Accept的感觉好爽代码: 1 void rotate(vector > &matrix) { 2 int n = matrix.size(); 3 i 阅读全文
posted @ 2014-02-06 17:18 小唯THU 阅读(340) 评论(0) 推荐(0) 编辑

2014年2月3日

摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).How many possible uni 阅读全文
posted @ 2014-02-03 20:32 小唯THU 阅读(730) 评论(0) 推荐(0) 编辑
摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).How many possible uni 阅读全文
posted @ 2014-02-03 15:06 小唯THU 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 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 nodes with keysless thanthe node's key.The right subtree of a node contains only nodes with keysgreater thanthe node's key.Both the left and ri 阅读全文
posted @ 2014-02-03 00:44 小唯THU 阅读(345) 评论(0) 推荐(0) 编辑

2014年2月2日

摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:对于树来说,自顶向下的递归是很好控制的,自底向上的递归就很容易让脑神经打结了。本来想仿照排序二叉树的中序遍历,逆向地由数组构造树,后来发现这样做需要先确定树的结构,不然会一直递归下去,不知道左树何时停止。代码:TreeNode *addNode(vector &num, int start, int end){ if(start > end) return NULL; int ... 阅读全文
posted @ 2014-02-02 19:27 小唯THU 阅读(764) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 10 下一页

导航