https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/564/
/**
* @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);
};
'Coding Test > LeetCode' 카테고리의 다른 글
[LeetCode] (Trees) Lv Easy. Maximum Depth of Binary Tree (0) | 2023.01.21 |
---|---|
[LeetCode] (Linked List) Lv Easy. Delete Node in a Linked List (0) | 2023.01.16 |
[LeetCode] (Strings) Lv Easy. Reverse Integer (0) | 2023.01.16 |
[LeetCode] (Array) Lv Easy. Remove Duplicates from Sorted Array (0) | 2023.01.14 |
[LeetCode] (Array) Lv Easy. Find Target Indices After Sorting Array (0) | 2023.01.12 |
댓글