amazon oa

This commit is contained in:
Mhrooz 2024-05-28 16:33:16 +02:00
parent 9104fd9842
commit cd42299e73
3 changed files with 52 additions and 0 deletions

18
392-240527-pass/main.py Normal file
View File

@ -0,0 +1,18 @@
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
cnt = 0
idt_m = 0
for idx, chs in enumerate(s):
for idt, cht in enumerate(t[idt_m:]):
if cht == chs:
idt_m = idt + idt_m + 1
cnt += 1
print(idt_m, idt, cht)
break
if cnt == len(s): return True
return False
sol = Solution()
s = "axc"
t = "ahbgdc"
print(sol.isSubsequence(s,t))

15
9-240525-pass/main.py Normal file
View File

@ -0,0 +1,15 @@
class Solution:
def isPalindrome(self, x: int) -> bool:
s = str(x)
if len(s) % 2 == 0:
mid = len(s) // 2 - 1
for i in range(mid):
if s[i] != s[len(s) - i - 1]:
return False
return True
else:
mid = len(s) // 2
for i in range(mid):
if s[i] != s[len(s) - i - 1]:
return False
return True

19
sample.py Normal file
View File

@ -0,0 +1,19 @@
def makePowerNonDecreasing(power):
# Write your code here
res=0
gap=0
while len(power)>1:
power[1]+=res
print(power, res)
if power[1]>=power[0]:
power.pop(0)
else:
gap=power[0]-power[1]
res+=gap
power.pop(0)
power[0]+=gap
print(power, res)
return res
res = makePowerNonDecreasing([3,5,2,6,3])
print(res)