Ruby 4 lines


  • 0
    L
    def compare_version(version1, version2)
        v1 = version1.split(".")
        v2 = version2.split(".")
        (0...[v1.length, v2.length].max).each {|i| return v1[i].to_i <=> v2[i].to_i if v1[i].to_i != v2[i].to_i}
        return 0
    end
    

Log in to reply
 

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