scramble string at leetCode 87. sol: get all possible scrambled strings of s1, then compare if s2 is in it.
for 1-char: scramble("a") --> "a"
for 2-chars : scramble("ab") --> "ba"
for 3-chars: scramble("abc") --> "bac", "cba", "acb", "cba" for 4-chars: scramble("abcd") --> (a | bcd) + (ab | cd) + (abc | d)
for 5-chars: scramble("abcde") --> (a | bcde) + (ab | cde) + (abc | de) + (abcd | e)
from the enumaration, there is always a left-substring and a right-substring, and recursive in each substring. consider the push_back order, there are two: left->\right and right->\left at each two slibings.
additional routines: how to do substring join and how to delete duplicate string from string-vector.
|
|
How to write a completed code, meaning, always take care the boundaries correctly, no missing situations. It’s easy to start from scratch and achieve somewhere, but hard to be completed.