Skip to content

Instantly share code, notes, and snippets.

@micylt
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micylt/6ab4d1c965c734534846 to your computer and use it in GitHub Desktop.
Save micylt/6ab4d1c965c734534846 to your computer and use it in GitHub Desktop.
isPalindrome
// returns whether or not a given int passed in is a palindrome
public boolean isPalindrome(Queue<Integer> q) {
Stack<Integer> s = new Stack<Integer>();
boolean isPalindrome = true;
int qSize = q.size();
for (int i = 0; i < qSize; i++) {
s.push(q.peek());
q.add(q.remove());
}
while (!s.isEmpty()) {
int temp = q.peek();
q.add(q.remove());
if (s.pop() != temp) {
isPalindrome = false;
}
}
return isPalindrome;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment