Skip to main content

Leetcode - 459. Repeated Substring Pattern

· One min read

https://leetcode.com/problems/repeated-substring-pattern/

/**
* @param {string} s
* @return {boolean}
*/
var repeatedSubstringPattern = function (s) {
// s를 두 번 반복한 후, 첫 글자, 맨 마지막 글자를 제거한 후 그 안에 s가 들어있는지 판별
return s.repeat(2).slice(1, -1).includes(s);
};

Runtime: 106 ms, faster than 61.11% of JavaScript online submissions for Repeated Substring Pattern.

Memory Usage: 45 MB, less than 60.32% of JavaScript online submissions for Repeated Substring Pattern.