Conversation
600.java
Outdated
| @@ -56,5 +56,40 @@ In the previous example, the output of the entire sequence of operations can be | |||
| 2. Consider simulating the deque as a way to efficiently determine which operations were performed on it. For example, as above, if the first element of the input is a 4, simulate a deque having the elements 1 through 4 pushed into it. Since you do not know whether each element was pushed to the front or the back, try pushing it on both sides and figuring out which side is correct later in the simulation. | |||
There was a problem hiding this comment.
Next time, each line should no more than 80 characters. Easier for me to read the problem.
600.java
Outdated
| order[nums[i]] = i; | ||
| } | ||
| Deque<Integer> deque = new LinkedList<>(); | ||
| StringBuilder sb = new StringBuilder(); |
There was a problem hiding this comment.
what does sb stand for? String builder? Instead of repeating its type and giving no meaning for this variable, rename it!
600.java
Outdated
| if(deque.isEmpty() || order[deque.peekLast()] > order[i]){ | ||
| deque.offerLast(i); | ||
| sb.append("pushBack,"); | ||
| } |
600.java
Outdated
| Deque<Integer> deque = new LinkedList<>(); | ||
| StringBuilder sb = new StringBuilder(); | ||
| for(int i = 1, j = 0; j < n; j++){ | ||
| for(; i <= a[j]; i++){ |
There was a problem hiding this comment.
- where do yo declare this array a? Is this code can be compiled?
- what does a mean? I suppose you a is order. And you forget to change a to order here
There was a problem hiding this comment.
Ok, I was wrong, a is not order. Sounds like num. I hope you can update this.
| } | ||
| int[] order = new int[n]; | ||
| int[] order = new int[n + 1]; | ||
| for(int i = 0; i < n; i++){ |
There was a problem hiding this comment.
Ok, I am going to be a jerk here. I don't like order array because my head memory is so limited, and I can't remember those variable names. And I am a retard in programming, can you modify your code so there's no order array? Just nums and deque?
There was a problem hiding this comment.
The only way I can think of is to use TreeMap to keep the insertion order and map number with its order, can't really do without additional array or LinkedList to cache number and its insertion order.
No description provided.