Solution for Leetcode