摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Analysis: This approach cost time complexity O(n^3). 1. If points less than 2 or all points locate at the same position, just output the points number. 2. Find two points with different coordinates ... 阅读全文
posted @ 2013-12-13 14:36 WinsCoder 阅读(204) 评论(0) 推荐(0) 编辑
摘要: Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13&qu 阅读全文
posted @ 2013-12-13 04:02 WinsCoder 阅读(156) 评论(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-28 12:27 WinsCoder 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Implement pow(x,n).Recursive solution is easier to understand. It uses the divide-and-conquer approach, which also runs intime. The formula is shown below:And the code is quite simple and straightforward.Code:class Solution {public: double pow(double x, int n) { if(n==0) return ... 阅读全文
posted @ 2013-11-26 18:02 WinsCoder 阅读(333) 评论(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 / \ 2 2 / \ / \3 4 4 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iterati... 阅读全文
posted @ 2013-11-24 16:18 WinsCoder 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 1. Define Storage Classes and explain application domain.register- tell to the compiler for use a CPU register for fast aceess for that variable.auto- it's a variable created and initialized when it is defined. It is not visible outside of the block.static- defined inside ofthe function retain i 阅读全文
posted @ 2013-11-22 19:07 WinsCoder 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", &q 阅读全文
posted @ 2013-11-22 18:00 WinsCoder 阅读(150) 评论(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.Code:class Solution {public: int findBalance(TreeNode *node){ if(!node) ret... 阅读全文
posted @ 2013-11-19 04:29 WinsCoder 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list inO(nlogn) time using constant space complexity.Code:class Solution {public: ListNode *sortList(ListNode *head) { if(!head) return head; map> sortMap; vector sortVector; ListNode *anchor=new ListNode(0); anchor->next=head; ListNode *cur... 阅读全文
posted @ 2013-11-18 11:56 WinsCoder 阅读(211) 评论(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].Code:class Solution {public: int removeDuplicates(int A[], int n) { if(n<3) return n; int i=0;... 阅读全文
posted @ 2013-11-17 18:52 WinsCoder 阅读(138) 评论(0) 推荐(0) 编辑