2 ms·
list.size() The problem is, in Java and probably many others, that method computes the size in linear time by traversing the list. The javadocs for java.util.L
by anon4 12y ago
list.size()
The problem is, in Java and probably many others, that method computes the size in linear time by traversing the list. The javadocs for java.util.LinkedList note that this was a decision taken so that splitting a list at an arbitrary node, etc. could be a constant-time operation.