Last active
August 29, 2015 14:20
-
-
Save micylt/6ab4d1c965c734534846 to your computer and use it in GitHub Desktop.
isPalindrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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