在這兩種獲取 Linkedlist 中節(jié)點數(shù)的實現(xiàn)中,時間復雜度是否會發(fā)生變化? 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);}
2 回答
添加回答
舉報
0/150
提交
取消
