摘要: 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 as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at 阅读全文
posted @ 2014-03-09 21:43 七年之后 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Say 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.Have you been asked this question in an interview?Yesclass 阅读全文
posted @ 2014-03-09 21:17 七年之后 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Have you been asked this question in an interview?Yes思考:一开始没有考虑空格。去掉不合法空格+两次翻转,不需要额外空间。class Solution {public: void reverseWords(str 阅读全文
posted @ 2014-03-09 20:56 七年之后 阅读(318) 评论(0) 推荐(0) 编辑
摘要: Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region.For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X X X XX X X XX X X 阅读全文
posted @ 2014-03-09 13:41 七年之后 阅读(259) 评论(0) 推荐(0) 编辑