If you have a better solution, feel free to open a PR. Add a small summary of your solution with space and time complexities. Make sure your code passes all the test cases on LeetCode for the problem ...