Meta tags:
description= We can scramble a string s to get a string t using the following algorithm: If the length of the string is 1, stop. If the length of the st...;
keywords= leetcode, javascript, solutions, algorithms, data structures, coding, programming, coding challenges, coding problems, coding solutions;
author= LeetCodeJavascript.com;
Headings (most frequently used words):
87, scramble, string, problem, description, solution,
Text of the page (most frequently used words):
#string (12), the (12), return (7), dfs (6), length (4), result (4), two (4), const (3), new (3), array (3), fill (3), and (3), substrings (3), scramble (3), leetcodejavascript (2), com (2), param (2), function (2), map (2), null (2), let (2), false (2), same (2), following (2), step (2), view (2), github (2), leetcode (2), solutions (2), 2025, josh, crozier, boolean, var, isscramble, for, solution, given, strings, true, scrambled, otherwise, apply, recursively, each, randomly, decide, swap, keep, them, order, after, this, may, become, split, into, non, empty, random, index, divide, where, stop, can, get, using, algorithm, problem, description, dynamic, programming, hard, back, all, star, javascript,
Text of the page (random words):
87 scramble string leetcode javascript solutions leetcodejavascript com star on github back to all solutions 87 scramble string hard view on leetcode view on github string dynamic programming problem description we can scramble a string s to get a string t using the following algorithm if the length of the string is 1 stop if the length of the string is 1 do the following split the string into two non empty substrings at a random index i e if the string is s divide it to x and y where s x y randomly decide to swap the two substrings or to keep them in the same order i e after this step s may become s x y or s y x apply step 1 recursively on each of the two substrings x and y given two strings s1 and s2 of the same length return true if s2 is a scrambled string of s1 otherwise return false solution param string s1 param string s2 return boolean var isscramble function s1 s2 const n s1 length const dp new array n fill map new array n fill map new array n fill null function dfs i1 j1 i2 if dp i1 j1 i2 null return dp i1 j1 i2 if i1 j1 return dp i1 j1 i2 s1 i1 s2 i2 const j2 j1 i1 i2 let result false for let i i1 i j1 i result result dfs i1 i i2 dfs i 1 j1 i2 i i1 1 dfs i1 i j2 i i1 dfs i 1 j1 i2 return dp i1 j1 i2 result return dfs 0 n 1 0 2025 leetcodejavascript com josh crozier
|