python - 时间有限执行: Loops or Recursion?

标签 python c recursion

我有一个问题,我确实使用简单的循环解决了它。但该计划的时间限制很紧。我能否使用某些函数的递归调用获得更好的执行时间?

long int calcMis(char *string,int i, int j,int len)
{
     long int mis=0;
     for(int k=0;k<len;k++)
     {
             if((mis+len-k)<=max)
                 return mis;

             if(string[i+k]!=string[j+k])
                mis++;

             if(mis>max)
                 return -1;
     }
     return mis;
}

最佳答案

已经有很多关于这个主题的话题了。 Is recursion ever faster than looping?Why is recursion in python so slow?在第一个谷歌搜索页面中产生...

关于python - 时间有限执行: Loops or Recursion?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18150720/

相关文章:

python - 使用 scipy 发行版运行 RandomizedSearchCV 时出现 "OverflowError: Python int too large to convert to C long"

Pythonlogging.conf重新加载配置

python - 使用 BeautifulSoup 将所有 href 抓取到列表中

Python - 定义仅使用一次的常量变量的最便捷方式

c - C 中的枚举声明是什么意思?

java - 递归方法中的多线程

c - 链接共享对象时对 `test' 的 undefined reference

c - 为什么不在我的代码中添加#include<linux/sched.h>,代码无法识别 task_struct 结构

c - 用 C 编写递归函数打印 1 和 n 个零

python - 使用递归替换 goto