正文内容加载中...
posted @ 2014-10-24 12:32 假日笛声 阅读(574) 评论(0) 推荐(0) 编辑
摘要: Emacs如此优秀的编辑器,如果输入中文不顺畅,不免遗憾。可惜现实是折腾很久也未必用得称心如意,作为一个重度(也许是中毒) Emacs使用者,根据个人经验写下此文,希望对同道中人有所帮助。在Windows下,我们可以使用Windows下的任何输入法; 但在Linux下却不行,如需使用ibus或者sc... 阅读全文
posted @ 2014-01-29 16:02 假日笛声 阅读(14240) 评论(2) 推荐(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 alternate between).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its zigzag level order traversal as:[ [3], ... 阅读全文
posted @ 2013-12-05 12:51 假日笛声 阅读(170) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Solution: 1 TreeNode *sortedListToBST(ListNode *head) { 2 if(head == NULL) 3 return NULL; 4 if(head->next == NULL) 5 return new TreeNode(head->val)... 阅读全文
posted @ 2013-11-29 07:41 假日笛声 阅读(157) 评论(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 depth of the two subtrees ofeverynode never differ by more than 1.Solution: 1 bool helperBalanced(int *depth, TreeNode * root){ 2 if(root->left... 阅读全文
posted @ 2013-11-29 07:22 假日笛声 阅读(166) 评论(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 leaf node.Summary: BFS or DFS with recursion. 1 int minDepth(TreeNode *root) { 2 if(root == NULL) 3 return 0; 4 if(root-... 阅读全文
posted @ 2013-11-29 06:34 假日笛声 阅读(148) 评论(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 @ 2013-11-29 05:16 假日笛声 阅读(218) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should return length =5, and A is now[1,1,2,2,3].Solution: 1 int removeDuplicates(int A[], int n) { 2 if(n = 2){17 //remove A[i]18 ... 阅读全文
posted @ 2013-11-27 15:50 假日笛声 阅读(135) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6click to show hints.Hints:If y... 阅读全文
posted @ 2013-11-27 15:15 假日笛声 阅读(184) 评论(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 complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).Solution: D 阅读全文
posted @ 2013-11-27 14:28 假日笛声 阅读(172) 评论(0) 推荐(0) 编辑