1publicintmaxProfit(int[] prices) {2intprofit = 0;3for(inti = 1; i < prices.length; i++) {4if(prices[i] - prices[i - 1] > 0)5profit += (prices[i] - prices[i - 1]);6}7returnprofit;8} 证明过程详见: http://tech-wonderland.net/blog/leetcode-best-time-to-buy-and-sell...
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 at mosttwotransactions. Note: You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy...
Say you have an array for which the ith element is the price of a given stock on day i. 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. 思路分析: 给定一个数组,数组中第i...
You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. 要点 input: prices->list[int] outp...
Say you have an array for which theith element 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 mul...
Can you solve this real interview question? Best Time to Buy and Sell Stock IV - You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k. Find the maximum profit you can achieve. You may compl
Can you solve this real interview question? Best Time to Buy and Sell Stock III - You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may complete at most two transacti
来自专栏 · LeetCode算法刷题 Problem description: Say you have an array price for while the i 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(you must sell the stock before buy again) ...
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...
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) with the following restrictions: You may not engage in multiple transactions at the same time (ie, you must sell the stock before...