File tree 1 file changed +65
-0
lines changed
1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 459. Repeated Substring Pattern
2
+
3
+ - Difficulty: Easy.
4
+ - Related Topics: String, String Matching.
5
+ - Similar Questions: Find the Index of the First Occurrence in a String, Repeated String Match.
6
+
7
+ ## Problem
8
+
9
+ Given a string ` s ` , check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.
10
+
11
+
12
+ Example 1:
13
+
14
+ ```
15
+ Input: s = "abab"
16
+ Output: true
17
+ Explanation: It is the substring "ab" twice.
18
+ ```
19
+
20
+ Example 2:
21
+
22
+ ```
23
+ Input: s = "aba"
24
+ Output: false
25
+ ```
26
+
27
+ Example 3:
28
+
29
+ ```
30
+ Input: s = "abcabcabcabc"
31
+ Output: true
32
+ Explanation: It is the substring "abc" four times or the substring "abcabc" twice.
33
+ ```
34
+
35
+
36
+ ** Constraints:**
37
+
38
+
39
+
40
+ - ` 1 <= s.length <= 104 `
41
+
42
+ - ` s ` consists of lowercase English letters.
43
+
44
+
45
+
46
+ ## Solution
47
+
48
+ ``` javascript
49
+ /**
50
+ * @param {string} s
51
+ * @return {boolean}
52
+ */
53
+ var repeatedSubstringPattern = function (s ) {
54
+ return ` ${ s}${ s} ` .slice (1 , s .length * 2 - 1 ).includes (s);
55
+ };
56
+ ```
57
+
58
+ ** Explain:**
59
+
60
+ nope.
61
+
62
+ ** Complexity:**
63
+
64
+ * Time complexity : O(n).
65
+ * Space complexity : O(n).
You can’t perform that action at this time.
0 commit comments