Introduction
It is time to look into the answer of extra sweet. I started to review editorial notes, look into the leaderboard, and also study test cases. I found the code to study, here is the Java code.
Code study
As a programmer, it is very important to be able to understand the algorithm in small detail. For some reason, I miss the important clue to solve the problem.
I spent time to look into the code and then finally I understood the idea by studying one of Java submission. Here is the Java code.
Starting from 7:10 am, now it is 8:20 pm, I never had such great time to study those code submissions and concentrated the problem solving.
Here is the design to study through the above Java code:
In the contest, I tried to set up the double linked list, and I like to set up 0's next points to 6, and 6's previous link to 0. Compared to the study code, no array is need. Just set up a map to add 1 as key, 6 as value, and then 5 as key and 0 as its value.
No comments:
Post a Comment