JAVA_LeetCode 122_Best Time to Buy and Sell Stock II 풀이 class Solution { public int maxProfit(int[] prices) { // 인접한 수의 차감된 수가 0보다 큰경우 반환값에 계속 더해준다. int profit = 0; for(int i = 0; i < prices.length - 1; i++) profit += Math.max(0, prices[i + 1] - prices[i]); return profit; } } 인접한 수와 차감된 수를 찾아서 해당 값을 더해나간다. * 출처 https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii...
JAVA_LeetCode 122_Best Time to Buy and Sell Stock II에 대한 요약내용입니다.
자세한 내용은 아래에 원문링크를 확인해주시기 바랍니다.