如何计算此功能的时间复杂度 [英] How to calculate time complexity for this function
本文介绍了如何计算此功能的时间复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ListNode FindnthToLast(int n) {
if (n <1 || headNode == null)
return null;
ListNode pntr1 = headNode, pntr2 = headNode;
//advance pntr2 by n-1 nodes;
for (int i = 0; i < n - 1; ++i) {
if (pntr2 == null) {
return null;
}
else //go to the next node
pntr2 = pntr2.getNext();
}
while(pntr2.getNext() != null)
{
pntr1 = pntr1.getNext();
pntr2 = pntr2.getNext();
}
return pntr1;
}
推荐答案
在这里,您可以找到有关如何计算函数时间复杂度的说明:
http://blogs.msdn.com/b/nmallick/archive/2010/03/30/how-to-calculate -time-complexity-for-a-given-algorithm.aspx [ ^ ]
这篇关于如何计算此功能的时间复杂度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文