本文介绍了更快的速度:嵌套循环还是连续循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

哪个更快,连续for循环或一堆嵌套的循环,例如3个连续for循环或3个嵌套的for循环?一个会永远比另一个快吗?

Which is faster, successive for loops or a bunch of nested ones, for example, 3 successive for loops or 3 nested for loops? Will one always be faster than the other?

推荐答案

只要循环次数不多,成功的循环往往会更快.

Successive loops will tend to be faster as long as there aren't too many.

在嵌套循环中,对于参数n的每增加一次,您的时间就会增加n平方.通过连续循环,n的任何增加都会导致执行时间线性变化.

In a nested loop, for every increase in an argument n you could have an increase in time that is n squared. With successive loops any increase in n results in a linear change in execution time.

这篇关于更快的速度:嵌套循环还是连续循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:58