摘要: 题目: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).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in the array.思路: 不同于普通的B search, 此题需要判断左右哪 阅读全文
posted @ 2013-05-02 12:12 tanghulu321 阅读(106) 评论(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.思路:可以用recursive的方法,每次返回左右两个树的最小高度的最小值加1. 但是如果这个树不是完整二叉树,则需要在没有左树或者没有右树的情况下让没有的那一叉返回正无穷而不是0. 所以需要判断当root == NULL的时候,这个root是不是到最下面一层了。代码:clas 阅读全文
posted @ 2013-05-02 01:19 tanghulu321 阅读(93) 评论(0) 推荐(0) 编辑