1 Star 0 Fork 0

agony/LeetCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
87.ScrambleString.Test.cs 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
Kai Yang 提交于 2015-08-15 13:33 . Add shared code
using NUnit.Framework;
[TestFixture]
public class TestClass : TestClassBase
{
[TestCase(5, 5, 1000)]
public void TestMethod(int maxLength, int maxCharKinds, int repeatTimes)
{
Repeat(repeatTimes, () =>
{
var s1 = GenerateString(0, maxLength, 'a', (char)(maxCharKinds + 'a' - 1));
var s2 = GenerateString(0, maxLength, 'a', (char)(maxCharKinds + 'a' - 1));
var expectedResult = IsScramble(s1, s2);
var result = new Solution().IsScramble(s1, s2);
Assert.AreEqual(expectedResult, result, string.Format("s1: {0}. s2: {1}.", s1, s2));
});
}
private bool IsScramble(string s1, string s2)
{
if (s1.Length != s2.Length) return false;
if (s1 == s2) return true;
for (var i = 1; i < s1.Length; ++i)
{
var l1 = s1.Substring(0, i);
var l2 = s1.Substring(i);
var r1 = s2.Substring(0, i);
var r2 = s2.Substring(i);
if (IsScramble(l1, r1) && IsScramble(l2, r2)) return true;
r1 = s2.Substring(s2.Length - i);
r2 = s2.Substring(0, s2.Length - i);
if (IsScramble(l1, r1) && IsScramble(l2, r2)) return true;
}
//System.Console.WriteLine("s1: {0}. s2: {1}", s1, s2);
return false;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/agony2020/LeetCode.git
git@gitee.com:agony2020/LeetCode.git
agony2020
LeetCode
LeetCode
master

搜索帮助