摘要: Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired bythis... 阅读全文
posted @ 2015-07-23 12:31 鸭子船长 阅读(205) 评论(0) 推荐(0) 编辑
摘要: Given a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"]. 1 class ... 阅读全文
posted @ 2015-07-23 12:30 鸭子船长 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty... 阅读全文
posted @ 2015-07-23 12:30 鸭子船长 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Given an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times. The algorithm should run in linear time and in O(1) space.Hint:H... 阅读全文
posted @ 2015-07-23 12:29 鸭子船长 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota... 阅读全文
posted @ 2015-07-23 12:28 鸭子船长 阅读(205) 评论(0) 推荐(0) 编辑
摘要: Given an integer, write a function to determine if it is a power of two.1 bool isPowerOfTwo(int n) {2 if(n<=0)3 return false;4 if(n&(n-1... 阅读全文
posted @ 2015-07-23 12:27 鸭子船长 阅读(145) 评论(0) 推荐(0) 编辑
摘要: Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6... 阅读全文
posted @ 2015-07-23 12:26 鸭子船长 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front o... 阅读全文
posted @ 2015-07-23 12:26 鸭子船长 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space? 1 /** 2 * Definition for singly-li... 阅读全文
posted @ 2015-07-23 12:25 鸭子船长 阅读(229) 评论(0) 推荐(0) 编辑
摘要: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ... 阅读全文
posted @ 2015-07-23 12:24 鸭子船长 阅读(173) 评论(0) 推荐(0) 编辑