Leetcode Solution in Ruby