代码拉取完成,页面将自动刷新
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;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。