Update PseudoPalindromicPath.java #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Intuition
To begin with, let's think about how to determine that a set of numbers is a palindrome? It's very simple: in a set of numbers, only one element may not have a pair, all the others must have a pair.
Approach
So I decided to override the add method in ArrayList and check if there is an item in the list that we want to add. If such an element already exists, we will delete it. If there are 1 or 0 elements left in the ArrayList at the end, then all the numbers that we added to it earlier are a palindrome