""" 0344.1 - Reverse String - Solution 1 - Two-Pointer Swap """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def reverseString(self, s: List[str]) -> None:
"""Reverse String Function"""
left, right = 0, len(s) - 1
while left < right:
s[left], s[right] = s[right], s[left]
left += 1
right -= 1
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
s1 = ["h", "e", "l", "l", "o"]
Solution().reverseString(s1)
print(s1) # ["o", "l", "l", "e", "h"]
s2 = ["H", "a", "n", "n", "a", "h"]
Solution().reverseString(s2)
print(s2) # ["h", "a", "n", "n", "a", "H"]
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0344.2 - Reverse String - Solution 2 - Recursive Approach """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def reverseString(self, s: List[str]) -> None:
"""Reverse String Function"""
def helper(left: int, right: int) -> None:
if left >= right:
return
s[left], s[right] = s[right], s[left]
helper(left + 1, right - 1)
helper(0, len(s) - 1)
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
s1 = ["h", "e", "l", "l", "o"]
Solution().reverseString(s1)
print(s1) # ["o", "l", "l", "e", "h"]
s2 = ["H", "a", "n", "n", "a", "h"]
Solution().reverseString(s2)
print(s2) # ["h", "a", "n", "n", "a", "H"]
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()