RUBY help needed


  • 0
    A

    This is my very first method in Ruby. In my compiler seems to work fine but here I got error: "Expected answer Line 7: 'Solution' was not declared in this scope" (Your answer [1,2,3,4,5,6,7,8,9,11,12,15,22] - looks fine). Could you help?

    # @param {Integer} right
    # @return {Integer[]}
    def self_dividing_numbers(left, right)
    
        arr = []
        left.upto(right).each {|i| arr.push(i)}
        res = []
        arr.each { |x|
            if (x < 10) 
                res.push(x)
            else
                digits = []
                d = x
                while (d > 0) do
                    digits.push(d % 10)
                    d = d / 10
                end
                tmp = 0
                digits.each { |i|
                    if ( i != 0 && x % i == 0)
                        tmp += 1
                    end
                }
                if (tmp == digits.size)
                    res.push(x)
                end
            end
        }
        res
    end

Log in to reply
 

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