Skip to content

Instantly share code, notes, and snippets.

@rejoycesong
Last active April 15, 2020 07:18
Show Gist options
  • Save rejoycesong/502006d54d09763172701ae398bfe02c to your computer and use it in GitHub Desktop.
Save rejoycesong/502006d54d09763172701ae398bfe02c to your computer and use it in GitHub Desktop.
class Solution:
def stringShift(self, s: str, shift: List[List[int]]) -> str:
shifted_amount = sum(i[1] if i[0] else -i[1] for i in shift) % len(s)
if shifted_amount == 0:
return s
else:
return s[-shifted_amount:] + s[:-shifted_amount]
# cleaner
class Solution:
def stringShift(self, s: str, shift: List[List[int]]) -> str:
shifted_amount = sum(i[1] if i[0] else -i[1] for i in shift) % len(s)
return s[-shifted_amount:] + s[:-shifted_amount]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment