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 ...
随机推荐
- JDK源码包结构分类
最近查看JDK源码时,无意间发现几个类在陌生包里:com.sun.*.sun.*.org.*,google了一把总结了下以备他人搜索,如内容有误欢迎指正! Jre库包含的jar文件(jdk1.6) ...
- ssh 协议执行repo sync 报错:Permission denied (publickey)
1.ssh key 已经添加ssh key到gerrit服务器,并且执行ssh协议的git clone可以正常克隆代码到本地,可见不是ssh key的问题. 2.manifest清单文件配置 最初在m ...
- 使用属性动画简单实现view飞入效果
比较简单的效果,可以用来菜单飞入之类,作为记录吧, package com.test.animation; import android.app.Activity; import android.os ...
- 关于MOD
同余式:正整数a,b对p取模,它们的余数相同,(a % p)=(b % p) 记做 或者a ≡ b (mod p). 运算规则 模运算与基本四则运算有些相似,但是除法例外.其规则如下: ...
- UUID生成
>>>Arch Linux # uuidgen From: http://os.51cto.com/art/200709/56613.htm >>>Debian j ...
- VBS定时关闭的弹窗
'类似msgbox '定时停留弹出框函数 Sub Print(text,timeout,title) Dim WshShell Set WshShell = CreateObject( ...
- Maven实战(二)构建简单Maven项目
上一节讲了maven的安装和配置,这一节我们来学习一下创建一个简单的Maven项目 1. 用Maven 命令创建一个简单的Maven项目 在cmd中运行如下命令: mvn archetype:gene ...
- sqoop1.99.6 update导出语句
我们采用sqoop-export插入数据的时候,如果主键已经存在了,插入会失败.想要根据主键判断是否要进行insert操作还是update操作,sqoop提供了update语法.示例 sqoop -- ...
- ---解决git pull 后出现冲突的解决方法
0. git statusOn branch masterYour branch and 'origin/master' have diverged,and have 1 and 3 differen ...
- 8.11 CSS知识点4
边框样式 1.边框宽度 border-width:medium | thin | thick | length border-top-width 设置上边框宽度 border-bottom-widt ...