Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 427 Bytes

1441. Build an Array With Stack Operations.md

File metadata and controls

22 lines (18 loc) · 427 Bytes

Code for ' 1441. Build an Array With Stack Operations ' (Python)

class Solution:
  def buildArray(self, target: List[int], n: int) -> List[str]:
    ans = []
    i = 0  # Target pointer
    num = 1  # Curr num

    while i < len(target):
      t = target[i]
      if t == num:
        ans.append("Push")
        i += 1
      else:
        ans.append("Push")
        ans.append("Pop")
      num += 1

    return ans