amazon oa
This commit is contained in:
parent
9104fd9842
commit
cd42299e73
18
392-240527-pass/main.py
Normal file
18
392-240527-pass/main.py
Normal 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
15
9-240525-pass/main.py
Normal 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
19
sample.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user