From 5f916962ba0b82f8a7e98ddbddb3e7b8c218fe3b Mon Sep 17 00:00:00 2001 From: Alexey Ilyukhov Date: Sat, 10 Oct 2020 02:37:31 +0300 Subject: [PATCH] Add 1499. Max Value of Equation --- LeetCode/1499_Max_Value_of_Equation.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 LeetCode/1499_Max_Value_of_Equation.py diff --git a/LeetCode/1499_Max_Value_of_Equation.py b/LeetCode/1499_Max_Value_of_Equation.py new file mode 100644 index 0000000..4c1f330 --- /dev/null +++ b/LeetCode/1499_Max_Value_of_Equation.py @@ -0,0 +1,23 @@ +class Solution(object): + def findMaxValueOfEquation(self, points, k): + """ + :type points: List[List[int]] + :type k: int + :rtype: int + """ + ans = None + + d = deque() + for x, y in points: + while len(d) > 0 and d[0][0] < x - k: + d.popleft() + + if len(d) != 0: + ans = max(ans, x + y + d[0][1] - d[0][0]) + + while (len(d) != 0) and d[-1][1] - d[-1][0] < y - x: + d.pop() + + d.append((x, y)) + + return ans