My Ruby solution is not working


  • 0
    H

    Here is my Ruby implementation of this problem

    def move_zeroes(nums)
        number_of_zero = nums.count(0)
        nums.delete(0)
        return (nums + number_of_zero.times.map{ 0 })
    end
    

    this is giving expected output on my local computer. If I run this on here it does not add zeros to remaining number array. For sample input [0,1,0,3,12,0,2] my computer's irb generate outpur [1,3,12,2,0,0,0] but here [1,3,12,2]. I have tested my solution with following ruby versions

       ruby-1.9.3-p392 [ x86_64 ]
       ruby-1.9.3-p547 [ x86_64 ]
       ruby-2.0.0-p481 [ x86_64 ]
       ruby-2.1.0 [ x86_64 ]
       ruby-2.1.1 [ x86_64 ]
       ruby-2.1.2 [ x86_64 ]
       ruby-2.1.3 [ x86_64 ]
       ruby-2.2.2 [ x86_64 ]
       ruby-2.2.3 [ x86_64 ]
       ruby-2.2.4 [ x86_64 ]
       ruby-2.2.5 [ x86_64 ]
       ruby-2.3.1 [ x86_64 ]
    =* ruby-2.3.3 [ x86_64 ]
    

    Any kind of help appreciated. Thanks.


Log in to reply
 

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