Runtime Error Exception in thread main java.util.EmptyStackException at java.util.Stack.peek(Stack.java:102) at Solution.validStackPermutation(Solution.java:16) at Runner.executeAndPrintOutput(Runner.java:61) at Runner.main(Runner.java:73)
while (!s.empty() && s.peek() == other.get(j)) { s.pop(); j++; } if (j <=other.size() && s.peek() == other.get(j)) { return false; } } return true; } }
while (!s.empty() && s.peek() == other.get(j)) { // if condition is never met, you quit loop when s is empty s.pop(); j++; } if (j <=other.size() && s.peek() == other.get(j)) { // how do you know that s is not empty at this point ? return false; } } return true; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)