Q:
Assume you have a method isSubstring which checks if one word is a
substring of another. Given two strings, si and s2, write code to check if s2 is
a rotation of si using only one call to isSubstring (e.g.,"waterbottle"is a rota-tion of "erbottlewat").
A:
idea:
s1 = xy
s2 = yx
那既然,单独的,这样,无法直接得到。
我们就想办法,给他们增大(增长) 。
例如:
s2 = yz
s1" = s1+s1 = xyxy
然后,就可以用:isSubstring()了。
当然,还是要check the string length.
Mistake:
刚开始,又是没有看明白题目。 难怪,感觉太简单了呢。
并不是全部的, s1.length的rotation,可能仅仅是rotatte了一部分。
哎, 看不明白题目,害死人啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以后面试的时候,一定要多问一下面试官,确认自己搞明白了题目。
Learned:
这个,因为刚开始看错了题目。
看了一眼答案。 (只看了s1=xy)给了提示。
哎,还是自己不够聪明阿
No comments:
Post a Comment