Generate all permutations of the input array and output them.
I kept getting Output Limit Exceeded and couldn’t figure out why.
I remembered asking a friend about it, and he said my output was larger than expected. The judge gave OLE after checking.
That felt even worse than getting TLE – at least with TLE I could optimize my code!
Later I wondered if there were duplicate elements in the array. I tried checking for duplicates before inserting into the vector, but still got OLE.
Finally I gave up and looked at other people’s solutions. The approach was the same as mine.
Then I suddenly noticed there’s a problem called Permutations II, which says the data may contain duplicates – meaning this problem’s data should NOT have duplicates!
Looking more carefully at others’ code, I noticed something more professional: vector.clear().
Just that one line was missing.
After adding it – Accepted!
Here is the code (a bit rough):
| |