What's wrong in my Ruby code?

  • 0

    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

    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

    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.