LeetCode Solution. Java