My ruby solution


  • 2
    T
    def compare_version(version1, version2)
        v1, v2 = version1.split('.'), version2.split('.')
        if (temp = v1.size - v2.size) > 0
            temp.times do v2 << '0' end
        else 
            (-temp).times do v1 << '0' end
        end
        v1.size.times do |i|
            temp = v1[i].to_i - v2[i].to_i
            next if temp == 0
            return temp > 0 ? 1 : -1
        end
        0
    end

Log in to reply
 

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