摘要: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array. 1 public static bool SearchinRotatedSortedAarrayII(int[] A, int target) 2 { 3 ... 阅读全文
posted @ 2012-10-16 23:51 ETCOW 阅读(395) 评论(0) 推荐(0) 编辑
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 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. 1 public static int ... 阅读全文
posted @ 2012-10-16 23:22 ETCOW 阅读(228) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found in the array, return [-1, -1].For example,Given [5, 7, 7, 8, 8, 10] and target value 8,return [3, 4]. 1 阅读全文
posted @ 2012-10-16 22:47 ETCOW 阅读(289) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.For example,Consider the following matrix:[[1, 3.. 阅读全文
posted @ 2012-10-16 22:25 ETCOW 阅读(191) 评论(0) 推荐(0) 编辑
摘要: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 1 public static bool SameTree(BTNode p, BTNode q) 2 { 3 if (p == null && q == null) 4 ... 阅读全文
posted @ 2012-10-16 22:12 ETCOW 阅读(234) 评论(0) 推荐(0) 编辑
摘要: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great":great / \gr eat/ \ / \g r e at / \ a tTo scramble the string, we may choose any non-leaf node and swap its two ... 阅读全文
posted @ 2012-10-16 06:01 ETCOW 阅读(536) 评论(0) 推荐(0) 编辑