上一页 1 2 3 4 5 6 ··· 18 下一页
摘要: 题目:二叉树的结点定义如下:structTreeNode{intm_nvalue;TreeNode* m_pLeft;TreeNode* m_pRight;};输入二叉树中的两个结点,输出这两个结点在数中最低的共同父结点。递归版本:空间O(1),时间O(n) 1 struct Node 2 { 3 int val; 4 Node *left; 5 Node *right; 6 Node():left(NULL), right(NULL){} 7 }; 8 9 Node *findFather(Node *root, Node *node1, Node *nod... 阅读全文
posted @ 2012-11-26 12:01 chkkch 阅读(1202) 评论(0) 推荐(2) 编辑
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps.For example:Given array A =[2,3,1,1,4]The minimum n 阅读全文
posted @ 2012-11-25 20:53 chkkch 阅读(1672) 评论(0) 推荐(0) 编辑
摘要: Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2.Another example is")()())", where the longest 阅读全文
posted @ 2012-11-25 20:26 chkkch 阅读(2290) 评论(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 still work?Note:You may only use constant extra space.For example,Given the following binary tree, 1 / \ 2 3 / \ \ 4 5 ... 阅读全文
posted @ 2012-11-25 20:08 chkkch 阅读(1900) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of 阅读全文
posted @ 2012-11-25 19:26 chkkch 阅读(1130) 评论(0) 推荐(0) 编辑
摘要: Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.Note:You are not suppose to use the l 阅读全文
posted @ 2012-11-25 17:45 chkkch 阅读(2120) 评论(1) 推荐(0) 编辑
摘要: 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 determine if a given target is in the array. 1 class Solution { 2 public: 3 int findPos(int a[], int left, int right) 4 { 5 if (left ... 阅读全文
posted @ 2012-11-25 14:40 chkkch 阅读(776) 评论(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 @ 2012-11-25 14:13 chkkch 阅读(805) 评论(0) 推荐(0) 编辑
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory.He 阅读全文
posted @ 2012-11-25 13:25 chkkch 阅读(995) 评论(0) 推荐(0) 编辑
摘要: Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals[1,3],[6,9], insert and merge[2,5]in as[1,5],[6,9].Example 2:Given[1,2],[3,5],[6,7],[8 阅读全文
posted @ 2012-11-25 12:10 chkkch 阅读(1521) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 18 下一页