We Just Swap elements of Left and Right Pointers and we increment left pointer ,decrement right pointer.
Python Code:
class Solution(object):
def reverseString(self, s):
l = 0
r = len(s) - 1
while l<r:
s[l],s[r] = s[r],s[l]
l+=1
r-=1
Alternative Single Line Code:
def reverseString(s):
s = s[::-1]
0 Comments