And if that's true is everything in the string, starting at the first element and removing the last element, a palindrome?
如果是相同的话,是不是字符串中的所有从第一个元素开始,并且删除最后一个元素后?
Code is right here. And all it's doing is when I'm getting into the different places I'm simply printing out information about where I am. What I want you to see palindrome is notice what happened here.
代码就在这儿,它的作用是当我运行到不同地方时,就输出我所在方位的信息,我想让你们看的就是注意这儿发生了什么,好了我调用了一个。
Palindrome 1 I'm going to give it a little indentation so that we can see this. OK.
应该是,我加一点儿缩进好让我们能看到它。
a I'm not, so come down here check palindrome that the two end points a and a are the same and call this again also.
判断两端都是,然后再次调用,注意发生了什么。
And I would suggest palindrome as a great example of that. That's easy to think about recursively. It's much harder to think about iteratively. And you want to get into the habit of deciding which is the right one for you to use. And with that, we'll see you next time.
其它的问题可能用递归的方式,可以更好的解决,而直接思考可能很困难,这时你就得养成做出,正确选择的好习惯了,下周再见。
There's the base case. If it's longer than one, what do I want to do? Well I'd like to check the two end points to see are they the same character? And if they are, then oh, I just need to know is everything else in the middle a palindrome?
如果只有一个元素也是回文,这是基本事件,如果比一个长的话那么我应该怎么做?,我将会查看两头是否相同?,如果是的,我只要知道中间剩下的部分是不是回文即可?
So this is to test whether a list is a palindrome.
我们可以把1放到数组里面作为第一个元素。
Only in New York, in Canada we pronounce it Palindrome.
你的方式来讲而我会按照我的方式来讲,对不起约翰。
It's not a palindrome.
数组不是回文的了。
OK. I'm calling palindrome with that.
它先访问了这个问题。
palindrome I'm going to call this palindrome 1.
我把它命名为。
Palindrome with a capital P.
它它当你来将这块的时候你会按照。
And one is the third element. And just return, it's done. It is a palindrome. That make sense.
完成,数组时回文的,这就对了,因为数组1a1从前面和从后面读都是一样的。
It tells me it is a palindrome. Well, it isn't really.
这就不对了,有bug出现了。
应用推荐