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 ...
随机推荐
- java maven诡异的错误no class found
从服务器下载一个java web项目,启动老提示no class found,查看maven依赖库,相关的jar包都已经引入.同样一个项目,在别的机器都可以运行,唯独在我本机运行出错. 为了排错,将其 ...
- 关于sql server远程访问Oracle数据库 OpenQuery查询返回多条数据的问题
在Sql Server远程访问Oracle 中的数据库表时: 远程语法通常为: select * from OpenQuery(Oracle链接服务器名称,‘查询语句’) eg: select * f ...
- .net一次连接执行多条sql语句
方法一: string SQLString="select 1; select 2;"; using (OdbcConnection connection = new OdbcCo ...
- 7. Reverse Words in a String
题目: Given an input string, reverse the string word by word. For example,Given s = "the sky is b ...
- asp.net中选择数字时,另外的数字同时发生变化(适用dev控件)
关键: <ClientSideEvents ValueChanged="AgioChanged" /> <div class="col-sm-4 ...
- JavaScript笔记:数据类型
javascript中有5种基本数据类型:Undefined,Null,Boolean,Number和String,还有一种复杂的数据类型--Object.javascript不支持任何创建自定义类型 ...
- spring 获取 bean
不通过注解或者是配置文件怎么获取spring中定义的bean呢?有几个方法: 1.实现ApplicationContextAware <bean class="com.xxx.Spri ...
- RAD 版本迁移工具,不怕升级麻烦了。
RAD 版本迁移工具,不怕升级麻烦了. http://community.embarcadero.com/blogs?view=entry&id=8865 migrationtool.exe ...
- redis基础使用
redis分linux,window两个版本分支. redis在window下的使用先下载相关包.下载地址:https://github.com/MSOpenTech/redis/releases 下 ...
- avalon2的后端渲染实践
avalon2为了提高性能,采用全新的架构,四层架构,其中一层为虚拟DOM. 虚拟DOM的一个好处是能大大提高性能,另一个好处是能过错整描述我们的页面结构.因此在非浏览器环境下,虚拟DOM也能正常运行 ...