Python submit question


  • 0
    K
    class Solution(object):
        def rotate(self,nums,k):
            n=len(nums)
            nums+=nums
            nums=nums[n-k:2*n-k]
            print(nums)
    
    s=Solution()         
    s.rotate([1,2],1)
    

    What above is my code, with version 3.5.1.
    And it runs find, but not cool with OJ. Have you guys met this before?
    And which version is OJ with?


  • 0

    Well you're not rotating the given array (list) at all. You're just doubling it:

    >>> s=Solution()
    >>> nums = [1,2]
    >>> s.rotate(nums, 1)
    [2, 1]                <==== NOBODY CARES
    >>> print(nums)
    [1, 2, 1, 2]          <==== WRONG
    

    The Python version is stated in the FAQ.


Log in to reply
 

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