摘要:
Best Time to Buy and Sell StockSay you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.//Time complexity O(n), auxi 阅读全文
posted @ 2013-05-17 16:22
Alan Yang
阅读(166)
评论(2)
推荐(0)
摘要:
Maximum difference between two elementsFrom http://www.geeksforgeeks.org/maximum-difference-between-two-elements/April 10, 2010Given an array arr[] of integers, find out the difference between any two elementssuch that larger element appears after the smaller number in arr[].Examples: If array is [2 阅读全文
posted @ 2013-05-17 14:58
Alan Yang
阅读(290)
评论(0)
推荐(0)
摘要:
Search a 2D MatrixWrite an efficient algorithm that searches for a value in anmxnmatrix. 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 m 阅读全文
posted @ 2013-05-17 00:18
Alan Yang
阅读(323)
评论(0)
推荐(0)
浙公网安备 33010602011771号