LeetCode Solution Java