From f4f315c657b2dcad5000555723fe49277d9e1483 Mon Sep 17 00:00:00 2001 From: Muhammad Khuzaima Umair Date: Fri, 3 Nov 2023 22:48:37 +0500 Subject: [PATCH] Create 1441_Build_an_Array_With_Stack_Operations.java --- ..._Build_an_Array_With_Stack_Operations.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 1441_Build_an_Array_With_Stack_Operations.java diff --git a/1441_Build_an_Array_With_Stack_Operations.java b/1441_Build_an_Array_With_Stack_Operations.java new file mode 100644 index 0000000..e6113c6 --- /dev/null +++ b/1441_Build_an_Array_With_Stack_Operations.java @@ -0,0 +1,24 @@ +// id: 1441 +// Name: Build an Array With Stack Operations +// link: https://leetcode.com/problems/build-an-array-with-stack-operations/ +// Difficulty: Medium + +class Solution { + public List buildArray(int[] target, int n) { + int j = 0; + List result = new ArrayList<>(); + for (int i = 1; i <= n && j < target.length; i++) { + if (i == target[j] ) { + result.add("Push"); + j++; + } else { + result.add("Push"); + result.add("Pop"); + } + } + + + return result; + + } +}