Why wont this work? Python


  • 0
    A
    firstElement = abs(len(nums) - k)
            nums = nums[firstElement:len(nums)] + nums[0:firstElement]
    

    This is working on my own pc but failing the same test cases in leetcode? I am modifying nums in place right?


  • 1
    3

    your modification should be in-place. use nums[:]= instead.


  • 1
    S

    nums[:] changes the pointer allocation,
    whereas the nums = creates a temp space allocation


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.