回文检查的递归方法 [英] Recursive method for palindrome checkup
本文介绍了回文检查的递归方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否甚至可以使用以下参数列表来定义回文检查的递归方法?
Is it even possible to define a recursive method for palindrome checkup with the following argument list?
int testPalindromeRecursive(char* str, int len) { ... }
注意:无需使用任何外部子功能或全局变量
Note: no external sub-functions or global variables have to be used
我认为这是不可能的,因为您必须以某种方式记住最后一个(前)索引位置.
I think this is impossible, because you have to remember the last (front) index position somehow.
推荐答案
是的,完全有可能-正如一些人提到的那样.
Yes, it is completely possible - as several people have mentioned.
基本案例:
- 如果len< = 1,则返回True
- 如果str [0]!= str [len-1]返回False
其他:用(str + 1,len -2)递归
Else: recurse with (str+1, len -2)
这篇关于回文检查的递归方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文