根据Open JDK中的实现,它是O(log N):
public K lastKey() {
return key(getLastEntry());
}
final Entry<K,V> getLastEntry() {
Entry<K,V> p = root;
if (p != null)
while (p.right != null)
p = p.right;
return p;
}
Run Code Online (Sandbox Code Playgroud)
该lastKey()呼叫getLastEntry(),继续走右子树,直到没有进一步的节点可走。由于实现将树保持在平衡状态,因此迭代次数为O(log N)。
| 归档时间: |
|
| 查看次数: |
1536 次 |
| 最近记录: |