miglss

65.YA

May 4th, 2025
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. def solve(arr: list) -> str:
  2.     def reverse(left, right):
  3.         while left < right:
  4.             arr[left], arr[right] = arr[right], arr[left]
  5.             left += 1
  6.             right -= 1
  7.  
  8.     left = 0
  9.  
  10.     for right in range(len(arr)):
  11.         if arr[right] == ' ':
  12.             reverse(left, right - 1)
  13.             left = right + 1
  14.  
  15.     reverse(left, right)
  16.  
  17.     return "".join(arr)
Advertisement
Add Comment
Please, Sign In to add comment