2280. Minimum Lines to Represent a Line Chart

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2280

class Solution:
    def minimumLines(self, stockPrices: List[List[int]]) -> int:
        stockPrices.sort()
        dx, dy = 0, 1
        res = 0
        for (x, y), (x1, y1) in pairwise(stockPrices):
            dx1, dy1 = x1 - x, y1 - y
            if dy * dx1 != dx * dy1:
                res += 1
            dx, dy = dx1, dy1
        return res