My LeetCode grinding. Trying to do a problem a day.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

main.py 593B

1234567891011121314151617181920
  1. class Solution:
  2. def stringShift(self, s, shift):
  3. currentIndex = 0
  4. for sh in shift:
  5. if sh[0] == 0:
  6. currentIndex += sh[1]
  7. else:
  8. currentIndex -= sh[1]
  9. # Now start reading string from this index (wrapping) and go until len reached
  10. retString = ""
  11. while len(retString) != len(s):
  12. retString += s[(currentIndex % len(s))]
  13. currentIndex += 1
  14. return retString
  15. s = Solution()
  16. print("Expected: cab")
  17. print("Got:", s.stringShift("abc", [[0,1], [1,2]]))