摘要: Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion? 解法1:不断除去n的因子3 阅读全文
posted @ 2016-01-29 16:33 AprilCheny 阅读(442) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2015-12-25 19:25 AprilCheny 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,... 阅读全文
posted @ 2015-12-16 10:20 AprilCheny 阅读(421) 评论(0) 推荐(0) 编辑
摘要: Follow upfor "Find Minimum in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Suppose a sort... 阅读全文
posted @ 2015-12-15 11:02 AprilCheny 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 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).Find the minimum element.You m... 阅读全文
posted @ 2015-12-15 09:33 AprilCheny 阅读(1021) 评论(0) 推荐(0) 编辑
摘要: Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解法:这题和由前序序列和中序... 阅读全文
posted @ 2015-12-14 18:43 AprilCheny 阅读(363) 评论(0) 推荐(0) 编辑
摘要: Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解法:前序遍历的第一个元素为树... 阅读全文
posted @ 2015-12-14 18:38 AprilCheny 阅读(529) 评论(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 a... 阅读全文
posted @ 2015-12-11 20:14 AprilCheny 阅读(187) 评论(0) 推荐(0) 编辑
摘要: Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjace... 阅读全文
posted @ 2015-12-11 11:31 AprilCheny 阅读(239) 评论(0) 推荐(0) 编辑
摘要: Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty... 阅读全文
posted @ 2015-12-09 15:16 AprilCheny 阅读(189) 评论(0) 推荐(0) 编辑