LeetCode OJ-- Scramble String ***@
https://oj.leetcode.com/problems/scramble-string/
一个字符串的混排变换,简直太妙了,好题
class Solution {
public:
bool isScramble(string s1, string s2) {
if(s1.size() != s2.size())
return false;
if(s1.size() == || s1 == s2)
return true;
string sa = s1;
string sb = s2;
sort(sa.begin(),sa.end());
sort(sb.begin(),sb.end());
if(sa != sb)
return false;
for(int i = ; i < s1.size(); i++)
{
string s11 = s1.substr(,i);
string s12 = s1.substr(i,s1.size() - i);
string s21 = s2.substr(,i);
string s22 = s2.substr(i,s2.size() - i);
string s31 = s2.substr(,s2.size() - i);
string s32 = s2.substr(s2.size() - i,s2.size());
if(isScramble(s11,s21)&&isScramble(s12,s22) || isScramble(s11,s32)&&isScramble(s12,s31))
return true;
}
return false;
}
};
LeetCode OJ-- Scramble String ***@的更多相关文章
- 【leetcode】Scramble String
Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two no ...
- [leetcode]87. Scramble String字符串树形颠倒匹配
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- [leetcode] 87. Scramble String (Hard)
题意: 判断两个字符串是否互为Scramble字符串,而互为Scramble字符串的定义: 字符串看作是父节点,从字符串某一处切开,生成的两个子串分别是父串的左右子树,再对切开生成的两个子串继续切开, ...
- [LeetCode] 87. Scramble String 搅乱字符串
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- [LeetCode] 87. Scramble String 爬行字符串
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- 【leetcode】 Scramble String (hard)★
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- Leetcode#87 Scramble String
原题地址 两个字符串满足什么条件才称得上是scramble的呢? 如果s1和s2的长度等于1,显然只有s1=s2时才是scramble关系. 如果s1和s2的长度大于1,那么就对s1和s2进行分割,划 ...
- leetcode@ [87] Scramble String (Dynamic Programming)
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- leetcode[86] Scramble String
将一个单词按照这种方式分: Below is one possible representation of s1 = "great": great / \ gr eat / \ / ...
- leetCode 87.Scramble String (拼凑字符串) 解题思路和方法
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
随机推荐
- 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...
- ssh整合(http://blog.csdn.net/songanling/article/details/22454973)
http://blog.csdn.net/songanling/article/details/22454973
- Angularjs-Dirty Checking
Angularjs实现了数据双向绑定,就像下面这样: <!doctype html> <htnl ng-app> <head> <script src=&qu ...
- c# winform TreeView NODE(节点) 重命名或获取节点修改后的值
在程序开发过程中我们经常用到treeview,还经常要修改节点的名字.节点名字修改后还想及时更新数据库.这时问题就来了,怎样获取NODE(节点)更新后的值呢?本人试了很多方法最终分析出treeview ...
- SQL Server 之AdventureWorks 2008 安
学习背景:<SQL Server 2008 编程入门经典> SQL Sever 版本 SQL Server 2008 R2 方法一: 1:AdventureWorks 2008 下载地址: ...
- sqlserver同步后在不重新初始化快照的情况下新增表
在已有事务复制中,时长需要新增表.索引,这些变更时不会同步到从库中.如果采用默认的设置,每次都需要重新初始化快照,从库重新应用快照和未执行的同步命令,这显然是无法在线上实践的方法.另一种 ...
- hive中order by,sort by, distribute by, cluster by作用以及用法
1. order by Hive中的order by跟传统的sql语言中的order by作用是一样的,会对查询的结果做一次全局排序,所以说,只有hive的sql中制定了order by所有的 ...
- 炫酷的时钟--canvas初体验
先啥也不说:来张效果图 我是根据:http://www.imooc.com/learn/133 这里的课程进行学习的.大大的感谢liuyubobobo老师的深入浅出的讲解!! 我在这里仅仅提供我自己的 ...
- html a tag's href javascript issue
a标签的href中写js中遇到的问题(ie中有问题,chrome没问题) <a class="free" href="javascript:{$('#suiteTy ...
- CRC
#define POLY 0x1021 /** * Calculating CRC-16 in 'C' * @para addr, start of data * @para num, length ...