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; + + } +}