/** * @param {string} s * @return {string[][]} */ var partition = function(s) { let path = []; let result = []; backtracking(0); return result;

functionbacktracking(index) { if (index >= s.length) { result.push([...path]); return; }

for (let i = index; i < s.length; i++) { if (isPalindrome(index, i)) { path.push(s.slice(index, i+1)); backtracking(i+1); path.pop(); } } }

functionisPalindrome(start, end) { let left = start; let right = end; while (left < right) { if (s[left] !== s[right]) returnfalse; left++; right--; } returntrue; }