Python, just use the common array to get AC. New Pythoner, don't understand much.
Just want to know why we use deque instead of array? Easier? Or faster?
- Python doesn't have arrays, or at least they're not called that. You mean lists.
- Deques are faster for certain operations. In particular, popping from the front is O(1) instead of O(n). Check https://wiki.python.org/moin/TimeComplexity.
Thank you! And another question: what is the difference between O(n) and O(k)? I didn't see it ever(learned a little C). Thank you again!
Sorry, I don't quite understand your question. The difference is that one uses n and the other uses k. Do you mean what the difference between n and k is? That depends on the context. If you mean on that page I showed, the page says:
Generally, 'n' is the number of elements currently in the container. 'k' is either the value of a parameter or the number of elements in the parameter.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.