Skip to content

Commit 602bad4

Browse files
committed
Runtime: 180 ms (Top 81.5%) | Memory: 18.96 MB (Top 17.6%)
1 parent 994d4d9 commit 602bad4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Runtime: 180 ms (Top 81.5%) | Memory: 18.96 MB (Top 17.6%)
2+
3+
class Solution:
4+
def maximumCostSubstring(self, s: str, chars: str, vals: List[int]) -> int:
5+
i=1
6+
m=dict()
7+
for c in ascii_lowercase:
8+
if c in chars:
9+
m.update({c:vals[chars.index(c)]})
10+
else:
11+
m.update({c:i})
12+
i+=1
13+
xx=[]
14+
for i in range(len(s)):
15+
xx.append(m[s[i]])
16+
print(xx)
17+
def maxSubArray(nums: List[int]) -> int:
18+
max_sum=nums[0]
19+
temp=0
20+
for i in range(len(nums)):
21+
if temp<0:
22+
temp=0
23+
temp+=nums[i]
24+
if temp>max_sum:
25+
max_sum=temp
26+
return max_sum
27+
28+
29+
30+
return max(maxSubArray(xx),0)

0 commit comments

Comments
 (0)