🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
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:** ~~~ Input: "abab" Output: True Explanation: It's the substring "ab" twice. ~~~ **Example 2:** ~~~ Input: "aba" Output: False ~~~ **Example 3:** ~~~ Input: "abcabcabcabc" Output: True Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.) ~~~ ![](https://img.kancloud.cn/c3/63/c36389c04b12b380bb0ba87e9faee17a_405x414.png) ![](https://img.kancloud.cn/ee/75/ee7587af2c6b1c5bacd1490643a02b94_923x134.png) ``` \1 就是匹配到至少2次 ``` ``` /** * @param {string} s * @return {boolean} */ var repeatedSubstringPattern = function(s) { var reg = /^(\w+)\1+$/ return reg.test(s) }; ``` ![](https://img.kancloud.cn/0c/99/0c99f1ca00be23ab013d2cb605a9261e_1043x390.png) ![](https://img.kancloud.cn/92/8e/928e08242ef41556ea38f0326575bd12_486x346.png) ``` var repeatedSubstringPattern = function(s) { return s.repeat(2).slice(1,-1).includes(s); }; ```