Created
March 14, 2016 06:56
-
-
Save jianminchen/65687cefd2b107ec5e23 to your computer and use it in GitHub Desktop.
Anagram - string.Remove function - good idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
class Solution { | |
static void Main(String[] args) { | |
int T = Convert.ToInt32(Console.ReadLine()); | |
string[] lines = new string[T]; | |
for (int i = 0; i < T; i++) | |
{ | |
lines[i] = Console.ReadLine(); | |
} | |
for (int i = 0; i < T; i++) | |
{ | |
if (lines[i].Length % 2 == 1) Console.WriteLine("-1"); | |
else | |
{ | |
string s1 = lines[i].Substring(0, lines[i].Length / 2); | |
string s2 = lines[i].Substring(lines[i].Length / 2); | |
int diff = 0; | |
for (int j = 0; j < s1.Length; j++) | |
{ | |
if (s2.Contains(s1[j].ToString())) | |
{ | |
s2 = s2.Remove(s2.IndexOf(s1[j]), 1); | |
} | |
else diff++; | |
} | |
Console.WriteLine(diff); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment