6 ms·
Though you have to be careful with that, because the obvious code for removing from a collection in reverse: for(i = list.size; i >= 0; i--) list.removeA
by jbri 15y ago
Though you have to be careful with that, because the obvious code for removing from a collection in reverse:
for(i = list.size; i >= 0; i--)
list.removeAt(i);
Is itself a schlemiel algorithm on any singly-linked list...
- kzrdude 15y agoYou're removing i+1 elements here :)
- willfarrell 15y agofor(i = list.size; i--;) list.removeAt(i);
- Confusion 15y agoThat really depends on the implementation of the linked list. I don't think it would actually behave O(n^2) in most implementations.