File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ class Solution {
292
292
```
293
293
294
294
Python:
295
- ``` python3
295
+ ``` py
296
296
class Solution :
297
297
def partition (self , s : str ) -> List[List[str ]]:
298
298
res = []
@@ -313,7 +313,38 @@ class Solution:
313
313
314
314
Go:
315
315
316
+ javaScript:
316
317
318
+ ``` js
319
+ /**
320
+ * @param {string} s
321
+ * @return {string[][]}
322
+ */
323
+ const isPalindrome = (s , l , r ) => {
324
+ for (let i = l, j = r; i < j; i++ , j-- ) {
325
+ if (s[i] !== s[j]) return false ;
326
+ }
327
+ return true ;
328
+ }
329
+
330
+ var partition = function (s ) {
331
+ const res = [], path = [], len = s .length ;
332
+ backtracking (0 );
333
+ return res;
334
+ function backtracking (i ) {
335
+ if (i >= len) {
336
+ res .push (Array .from (path));
337
+ return ;
338
+ }
339
+ for (let j = i; j < len; j++ ) {
340
+ if (! isPalindrome (s, i, j)) continue ;
341
+ path .push (s .substr (i, j - i + 1 ));
342
+ backtracking (j + 1 );
343
+ path .pop ();
344
+ }
345
+ }
346
+ };
347
+ ```
317
348
318
349
319
350
-----------------------
You can’t perform that action at this time.
0 commit comments