Skip to content

Instantly share code, notes, and snippets.

@agumonkey agumonkey/new.py
Created May 9, 2019

Embed
What would you like to do?
## based on airbnb proto interview
def rev(s):
return s[::-1]
# a .. b
# (a,b) .. (b,a)
def mir(a,b):
i = a
j = b
while i <= b and j >= a:
yield (i,j)
i += 1
j -= 1
# a .. b
# (a,b) .. (b,a)
def mig(a,b):
i = a
j = b
while i < j:
yield (i,j)
i += 1
j -= 1
yield (i,j)
def rev_(s):
if s:
l = len(s)
o = bytearray(l)
for (i,j) in mig(0,l-1):
o[j] = ord(s[i])
o[i] = ord(s[j])
return o.decode()
else:
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.