在这两种获取 Linkedlist 中节点数的实现中,时间复杂度是否会发生变化?
private int getCountIterative() {
Node start = head;
int count = 0;
while (start != null)
{
count++;
start = start.next;
}
return count;
}
private int getCountRecursive(Node node) {
if (node == null)
return 0;
return 1 + getCountRecursive(node.next);
}
温温酱
慕姐4208626
相关分类