Skip to content

Update PseudoPalindromicPath.java #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

makariyp
Copy link

@makariyp makariyp commented May 5, 2023

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant