Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
966 B
2
Indexable
Never
	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;
	}
Leave a Comment