Untitled
unknown
plain_text
2 years ago
966 B
6
Indexable
public static boolean numDigsInStack(Stack<Integer> s, int num) {
Stack<Integer> temp = new Stack<Integer>();
int numCopy = num;
int reverseNum = revNum(num);
int current;
for (int i = 0; i < countDigs(num); i++) {
while (!s.isEmpty()) {
current = s.pop();
temp.push(current);
boolean flag;
if (current == num % 10) {
flag= true;
num /= 10;
}else
flag=false;
if(!flag)
num=numCopy;
if (num == 0)
return true;
}
}
while(!temp.isEmpty()) {
s.push(temp.pop());
}
for (int i = 0; i < countDigs(num); i++) {
while (!s.isEmpty()) {
current = s.pop();
temp.push(current);
boolean flag;
if (current == num % 10) {
flag= true;
num /= 10;
}else
flag=false;
if(!flag)
num=numCopy;
if (reverseNum == 0)
return true;
}
}
while(!temp.isEmpty()) {
s.push(temp.pop());
}
return false;
}Editor is loading...
Leave a Comment