Skip to content

#600#2

Open
yuewang0319 wants to merge 4 commits intomasterfrom
600
Open

#600#2
yuewang0319 wants to merge 4 commits intomasterfrom
600

Conversation

@yuewang0319
Copy link
Copy Markdown
Collaborator

No description provided.

@tianheng tianheng self-requested a review April 26, 2017 16:21
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.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,");
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: } else {

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++){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants