Explanation

595.Check Whether a Stack Is Empty After Each Operation

Easy
Process ops on an initially empty stack: a positive number means push it, and 0 means pop (ignored if the stack is empty). After every operation, record 1 if the stack is empty and 0 if it is not. isEmptyisEmptyA stack operation that answers whether the stack currently holds no items. is the guard behind every safe pop and peek. This problem also shows a useful habit: notice which information a question really needs. Emptiness depends only on how many items are on the stack, so a single counter can replace the stack itself.

Example 1:

Input: ops = [7,0,0,3,8,0]

Output: [0,1,1,0,0,0]

Example 2:

Input: ops = [0,0]

Output: [1,1]

+ 3 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ ops.length ≤ 1000
  • ●0 ≤ ops[i] ≤ 1000000 (a positive value means push it, 0 means pop)

ops =

[7, 0, 0, 3, 8, 0]