Skip to content

Commit c0bf598

Browse files
committed
Add solution of 122, 134
1 parent a7a0d14 commit c0bf598

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

.idea/Algorithms.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LeetCode/Python3/00000-00500/00122.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def maxProfit(self, prices: List[int]) -> int:
6+
profit_sum = 0
7+
for i in range(1, len(prices)):
8+
tmp = prices[i] - prices[i-1]
9+
if tmp > 0:
10+
profit_sum += tmp
11+
return profit_sum

LeetCode/Python3/00000-00500/00134.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
6+
n = len(gas)
7+
for i in range(n):
8+
j = i
9+
remain = gas[i]
10+
while remain - cost[j] >= 0:
11+
remain = remain - cost[j] + gas[(j + 1) % n]
12+
j = (j + 1) % n
13+
if j == i:
14+
return i
15+
return -1

0 commit comments

Comments
 (0)