Hard
,String
,DP
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:
s
, divide it to x
and y
where s = x + y
.s
may become s = x + y
or s = y + x
.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
.
Example 1:
Example 2:
Example 3:
Constraints:
s1.length
== s2.length
s1.length
<= 30s1
and s2
consist of lowercase English letters.喜得TLE
Time: (?) 從一開始到切到最小有n…1種切法(n^2), 每個切法去比較s1每個位置跟s2的每個位置是否相符(n^2)
Extra Space:
Follow up:
XD March 31, 2023