-
Notifications
You must be signed in to change notification settings - Fork 15
/
StrSymmetryPoint.cs
48 lines (38 loc) · 976 Bytes
/
StrSymmetryPoint.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
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
public class Solution
{
public static void Main(string[] args)
{
Console.WriteLine(solution("racecar"));
}
public static int solution(string word)
{
if (word.Length % 2 != 1)
{
return -1;
}
int midPoint = word.Length / 2;
for (int i = 0; i < midPoint; i++)
{
if (word[i] != word[word.Length - 1 - i])
{
return -1;
}
}
return midPoint;
}
}
// tests
[TestMethod]
public void TestSolution()
{
Assert.AreEqual(Solution.solution("aabaac"), -1);
Assert.AreEqual(Solution.solution("racecar"), 3);
Assert.AreEqual(Solution.solution("aabbcc"), -1);
Assert.AreEqual(Solution.solution("aabbgbbaa"), 4);
Assert.AreEqual(Solution.solution("atoyotasatoyota"), 7);
}