leetcode record

66 plus one

思路:检测数字9,置初始位为1,pushback 0

bug:

Line 3: execution reached the end of a value-returning function without returning a value

2 for 循环中 是 i or n iterator

3 Line 11: return-statement with no value, in function returning 'std::vector<int>' [-fpermissive]

121 Best Time to Buy and Sell Stock (time exceeded)

Input: [7, 1, 5, 3, 6, 4]
Output: 5
max. difference = 6-1 = 5 (not 7-1 = 6, as selling price needs to be larger than buying price)

思路:一个for 遍历 result > max_profit则赋值,找arr min 并赋值

122. Best Time to Buy and Sell Stock II (ac)

Say you have an array for which the ith element is the price of a given stock on day i.

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 the same time (ie, you must sell the stock before you buy again).

思路:把前后相减>0的价格都加起来

169. Majority Element

bug:

Line 11: cannot convert 'std::vector<int>' to 'int' in return

 

 

posted @ 2018-01-14 21:58  furyunder  阅读(41)  评论(0编辑  收藏  举报