What's wrong in my Ruby code?


  • 0
    N

    My Ruby code :

    # @param {Integer[]} nums
    # @return {Integer}
    def remove_duplicates(nums)
        #print "new nums = #{nums.uniq} ; length of new nums = #{nums.uniq.length}"
        return nums.uniq.length
    end
    

    In Ruby, there is a method called "uniq" and it returns a new array by removing duplicate values in self. For example,

    a = [ "a", "a", "b", "b", "c" ]

    a.uniq => ["a", "b", "c"]

    I thought this question is a real "easy" one but I was wrong.
    The result when I do "Run Code" is below
    0_1510119527752_2017-11-08_133555.png

    Can anyone tell me why the "Run Code" result shows "array" instead "int"? I did return "int" in my code...

    return nums.uniq.length
    

    Thank you for your help.


Log in to reply
 

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