Skip to content

Commit 65cf244

Browse files
authored
Create 459-repeated-substring-pattern.js
1 parent 61dbcf3 commit 65cf244

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

459-repeated-substring-pattern.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
const repeatedSubstringPattern = function(s) {
6+
const len = s.length
7+
let tmp = ''
8+
for(let i = 1; i <= len; i++) {
9+
tmp = s.substr(0, i)
10+
if (tmp.length === len) {
11+
return false
12+
}
13+
if (s === genStr(tmp, len)) {
14+
return true
15+
}
16+
}
17+
return false
18+
};
19+
function genStr(sub, limit) {
20+
let str = sub
21+
while(str.length < limit) {
22+
str += sub
23+
}
24+
return str
25+
}

0 commit comments

Comments
 (0)