fork download
  1. def ReverseString(s, leftCharIndex, rightCharIndex):
  2. #base case
  3. if leftCharIndex >= rightCharIndex:
  4. return
  5. #swap the charcters
  6. s[leftCharIndex], s[rightCharIndex] = s[rightCharIndex], s[leftCharIndex]
  7.  
  8. return ReverseString(s, leftCharIndex+1, rightCharIndex-1)
  9.  
  10. s = ["h","e","l","l","o"]
  11. ReverseString(s, 0, len(s)-1)
  12. print(s)
Success #stdin #stdout 0.04s 9460KB
stdin
Standard input is empty
stdout
['o', 'l', 'l', 'e', 'h']