一道很简单的题。但是一直在调corner case,好不容易写完了再感受下速度和别人写的代码,差距太大了。心疼三秒钟。
Question:
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.
Example 1:
Example 2:
Example 3:
Explanation:
原理很简单,就是每次得到一个substring,往后检查相同长度的下一段string。要注意的是,遍历的index只要到length/2就行了,毕竟至少也要重复两遍的。