-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
38 lines (35 loc) · 977 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
namespace SplitTwoStringsToMakePalindrome
{
class Program
{
static void Main(string[] args)
{
string a = "pvhmupgqeltozftlmfjjde", b = "yjgpzbezspnnpszebzmhvp";
Console.WriteLine(CheckPalindromeFormation(a, b));
}
static bool CheckPalindromeFormation(string a, string b)
{
return Check(a, b) || Check(b, a);
}
static bool CheckPalindrome(string str, int li, int hi)
{
while (li < hi)
{
if (str[li++] != str[hi--])
return false;
}
return true;
}
static bool Check(string a, string b)
{
int li = 0, hi = a.Length - 1;
while (li < hi && a[li] == b[hi])
{
li++;
hi--;
}
return CheckPalindrome(a, li, hi) || CheckPalindrome(b, li, hi);
}
}
}