leetcode 87:Scramble String
2015-12-02 14:13
405 查看
题目:
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 =
To scramble the string, we may choose any non-leaf node and swap its two children.
For example, if we choose the node
string
We say that
Similarly, if we continue to swap the children of nodes
it produces a scrambled string
We say that
Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.
思路:
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 =
"great":
great / \ gr eat / \ / \ g r e at / \ a t
To scramble the string, we may choose any non-leaf node and swap its two children.
For example, if we choose the node
"gr"and swap its two children, it produces a scrambled
string
"rgeat".
rgeat / \ rg eat / \ / \ r g e at / \ a t
We say that
"rgeat"is a scrambled string of
"great".
Similarly, if we continue to swap the children of nodes
"eat"and
"at",
it produces a scrambled string
"rgtae".
rgtae / \ rg tae / \ / \ r g ta e / \ t a
We say that
"rgtae"is a scrambled string of
"great".
Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.
思路:
相关文章推荐
- https://camo.githubusercontent.com/a25916ccc96abf4f949ae55a3fc8b0108ac578a8/687474703a2f2f3764396f30
- SQLSERVER聚集索引和主键(Primary Key)的误区认识
- 对QP中RTC的理解
- Friendship of Frog(水题)
- python 学习笔记之一
- Android中的布局和控件
- 用于Lucene的各中文分词比较
- 堆和栈的区别
- 评分卡模型剖析(woe、IV、ROC、信息熵)
- 漫说代理模式---给宝宝成长护航
- 【LeetCode】Decode Ways
- Android Selector用法
- android 打开浏览器指定网页
- 搭建自己的Nuget服务器
- 往aws中的s3上传数据
- 泡泡
- gridview DataFormatString 属性设置须知
- http svn svn http
- Nim游戏博弈(收集完全版)
- 引入其他类