From 8da8fe0859ffc5bd4fc63cd17bf6d170aebd99c5 Mon Sep 17 00:00:00 2001 From: 622b169008dbb7338e377ec6 <622b169008dbb7338e377ec6@devide> Date: Wed, 26 Apr 2023 12:31:38 +0000 Subject: [PATCH] UPDATE --- 123.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 123.py diff --git a/123.py b/123.py new file mode 100644 index 0000000..7ef0487 --- /dev/null +++ b/123.py @@ -0,0 +1,19 @@ +class Solution(object): + def canCompleteCircuit(self, gas, cost): + """ + :type gas: List[int] + :type cost: List[int] + :rtype: int + """ + n = len(gas) + if sum(gas) < sum(cost): + return -1 + else: + start = 0 + path = 0 + for i in range(n): + path = path + (gas[i] - cost[i]) + if path < 0: + start = i + 1 + path = 0 + return start \ No newline at end of file -- GitLab