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 ...
随机推荐
- Windows下PHP版本选取
1. 下载地址 http://windows.php.net/download/ 2. PHP大版本 PHP4:由于太古老.对OO支持不力已基本被淘汰. PHP5:分为三个分支——PHP5.2之前的版 ...
- HTTP调试工具扩展
★Fiddler神器之一,IE-WinNet-Fiddler-Server,能跟踪调试HTTP和HTTPS是优点也是缺点. 地址:http://www.fiddler2.com/ ★Charles,可 ...
- [转载]: delphi中XLSReadWrite控件的使用(1)---简介
XLSReadWrite控件简介: 一个你需要的,能在Delphi和.NET下访问Excel文件的完美解决方案. 一个经典的读写Excel的控件,对于使用Excel 开发很有帮助 官方网站: http ...
- 百度地图API示例之设置地图显示范围
代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" cont ...
- CentOS6 vsftpd 安装及优化方法
我在每次配置ftp的时候都会一头雾水,一直也没总结一份特别完整有效的方法出来,这次特别记录一下,以备以后使用 1.安装vsftpd yum -y install vsftpd chkconfig vs ...
- dockerfile学习与详解
1,什么是dockerfile? dockerfile是相当于docker使用的一个脚本,作用是便于实现自定义的镜像image,用语docker build [OPTIONS] PATH ,只需要指定 ...
- 关于Eclipse项目中加入jquery.js文件报错(missing semicolon)问题
在使用Eclipse3.7及以后的版本的时候,加入jQuery文件会报错(missing semicolon),文件中会显示红色小X,虽然这个错误并不会影响项目的运行,但是这个却会大大的影响到开发人员 ...
- C语言提供了几个标准库函数 itoa() atoi()
C语言提供了几个标准库函数C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串.以下是用itoa()函数将整数转换为字符串的一个例子: # include <s ...
- LinQ 高级查询
高级查询 模糊查(包含):.Contains(name) 开头:.StartsWith(name) 结尾:.EndsWith(name) 个数:.Count() 最大值:Max(r => r.p ...
- 上传文件(单文件)(FormData)(前端代码+.NET服务器端)
由于样式需要不能直接用file,只能用文本框+按钮 <form class="form-horizontal form-bordered form-row-strippe" ...