Skip to content

Commit

Permalink
Create 1441_Build_an_Array_With_Stack_Operations.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhuzaima committed Nov 3, 2023
1 parent 6893237 commit f4f315c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 1441_Build_an_Array_With_Stack_Operations.java
Original file line number Diff line number Diff line change
@@ -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<String> buildArray(int[] target, int n) {
int j = 0;
List<String> 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;

}
}

0 comments on commit f4f315c

Please sign in to comment.