본문 바로가기
Coding Test/LeetCode

[LeetCode] (Array) Lv Easy. Best Time to Buy and Sell Stock II

by song.ift 2023. 1. 16.

https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/564/

 

Explore - LeetCode

LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.

leetcode.com

 

javascript
닫기
/** * @param {number[]} prices ​* @return {number} ​*/ var maxProfit = function (prices) { ​​​​return prices.reduce((a, c, i) => { ​​​​​​​​if (prices.length > i + 1 && 0 < prices[i + 1] - c) { ​​​​​​​​​​​​a += prices[i + 1] - c ; ​​​​​​​​} ​​​​​​​​return a; ​​​​}, 0); };

GitHub : https://github.com/developeSHG/Algorithm-LeetCode/tree/main/2089-find-target-indices-after-sorting-array

 

GitHub - developeSHG/Algorithm-LeetCode: 릿코드 소스코드

릿코드 소스코드. Contribute to developeSHG/Algorithm-LeetCode development by creating an account on GitHub.

github.com

 

댓글