Created
October 6, 2024 17:32
-
-
Save mohneesh7/6a764595e14eee349069eec394adaba0 to your computer and use it in GitHub Desktop.
Solution for Reverse String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solution for Reverse String | |
class Solution: | |
def reverseString(self, s: List[str]) -> None: | |
""" | |
Do not return anything, modify s in-place instead. | |
""" | |
# case check for single element | |
# if len(s) <= 1: | |
# return | |
left = 0 | |
right = len(s) - 1 | |
while left < right: | |
# temp = s[left] | |
# s[left] = s[right] | |
# s[right] = temp | |
# better way to swap | |
s[left], s[right] = s[right], s[left] | |
left += 1 | |
right -=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment