1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Reverse an array inplace without pointers using recursion in python [closed]

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    class Solution:
    def reverse(self, arr: list, n: int) -> None:
    if len(arr)-n>=n-1:
    return
    arr[len(arr)-n],arr[n-1]=arr[n-1],arr[len(arr)-n]
    self.reverse(arr,n-1)
    return arr

    s=Solution()
    print(s.reverse([1,2,3,4,5,6,7],7))


    here i uses len() instead of pointer.

    So this is a good choice or Is there any problem for using len()?

    Continue reading...

Compartilhe esta Página