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 ***@的更多相关文章

  1. 【leetcode】Scramble String

    Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two no ...

  2. [leetcode]87. Scramble String字符串树形颠倒匹配

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  3. [leetcode] 87. Scramble String (Hard)

    题意: 判断两个字符串是否互为Scramble字符串,而互为Scramble字符串的定义: 字符串看作是父节点,从字符串某一处切开,生成的两个子串分别是父串的左右子树,再对切开生成的两个子串继续切开, ...

  4. [LeetCode] 87. Scramble String 搅乱字符串

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  5. [LeetCode] 87. Scramble String 爬行字符串

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  6. 【leetcode】 Scramble String (hard)★

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  7. Leetcode#87 Scramble String

    原题地址 两个字符串满足什么条件才称得上是scramble的呢? 如果s1和s2的长度等于1,显然只有s1=s2时才是scramble关系. 如果s1和s2的长度大于1,那么就对s1和s2进行分割,划 ...

  8. 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 ...

  9. leetcode[86] Scramble String

    将一个单词按照这种方式分: Below is one possible representation of s1 = "great": great / \ gr eat / \ / ...

  10. leetCode 87.Scramble String (拼凑字符串) 解题思路和方法

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

随机推荐

  1. c#深拷贝

    /// <summary> /// 对象拷贝 /// </summary> /// <param name="obj">被复制对象</pa ...

  2. 编译错误:error: multi-line comment

    编译错误:error: multi-line comment  这其实是有宏定义的地方的问题. 原因是宏定义非一行,在宏定义的行尾使用 '\' 连接符导致的. 所以这个地方的注释使用 /*   */ ...

  3. sqlite 报错:database is locked

    在sqlite批量添加数据时,报错:database is locked. 解决办法:将db路径由相对路径设置为绝对路径.

  4. Nodejs日志管理包

    Nodejs日志管理工具包:log4js 和 winston 1.log4js的使用 1)package.json中加入依赖 "log4js":"~0.6.21" ...

  5. CGContextAddArcToPoint和CGContextAddArc

    比较难的是CGContextAddArcToPoint 代码如下: CGContextRef context=UIGraphicsGetCurrentContext(); CGContextSetRG ...

  6. git patch

    http://www.cnblogs.com/y041039/articles/2411600.html

  7. TCP/IP 之大明王朝邮差

    本系列文章全部摘选自"码农翻身"公众号,仅供个人学习和分享之用.文章会给出原文的链接地址,希望不会涉及到版权问题. 个人感言:真正的知识是深入浅出的,码农翻身" 公共号将 ...

  8. Linux:永久修改网卡的MAC地址

    比如:搭建一个虚拟机环境之后,需要N个一样的系统,可以本地复制虚拟机来实现.但是复制之后,网卡的MAC地址一样,无法使用,这时候需要修改网卡的MAC地址,且希望重启系统之后,仍生效的,步骤如下: 1. ...

  9. namke 命令行编译

    简介 大家已经习惯于微软提供的功能强大的IDE,已经很少考虑手动编连项目了,所谓技多不压身,有空的时候还是随我一块了解一下命令行编译. C/C++/VC++程序员或有Unix/Linux编程经验应该很 ...

  10. yum命令指南

    yum check-update  检查可更新的所有软件包 yum update  下载更新系统已安装的所有软件包yum upgrade  大规模的版本升级,与yum update不同的是,连旧的淘汰 ...