We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The hardest part, was getting my brain to refocus on this "Special Palindrone" definition. Originally I was coding for a normal palindrone, which is VASTLY different and more complicated. Once I wasted time on that and re-read the problem, the solution wasn't too difficult.
My Solution: C#
static long substrCount(string s)
{
long retVal = s.Length;
for (int i = 0; i < s.Length; i++)
{
var startChar = s[i];
int diffCharIdx = -1;
for (int j = i + 1; j < s.Length; j++)
{
var currChar = s[j];
if (startChar == currChar)
{
if ((diffCharIdx == -1) ||
(j - diffCharIdx) == (diffCharIdx - i))
retVal++;
}
else
{
if (diffCharIdx == -1)
diffCharIdx = j;
else
break;
}
}
}
return retVal;
}
Special String Again
You are viewing a single comment's thread. Return to all comments →
The hardest part, was getting my brain to refocus on this "Special Palindrone" definition. Originally I was coding for a normal palindrone, which is VASTLY different and more complicated. Once I wasted time on that and re-read the problem, the solution wasn't too difficult.
My Solution: C#