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.
It seems like my C# solution is sloppier compared to this dictionary version...
I am removing each character that doesn't match. Removing would decrease the length, that's where "i--" comes into play in my code.
privatestaticintGetChangeCountForAnagram2(stringtestCase){if(IsLengthOdd(testCase))returnNOT_POSSIBLE;// Parse test case for left and right textsintmiddleIndex=testCase.Length/2;varleft=testCase.Substring(0,middleIndex);varright=testCase.Substring(middleIndex);inttotal=0;for(inti=0;i<right.Length;i++){varc=right[i];intindex=left.IndexOf(c);if(index<0){right=right.Remove(i,1);total++;}else{left=left.Remove(index,1);right=right.Remove(i,1);}i--;}returntotal;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →
It seems like my C# solution is sloppier compared to this dictionary version... I am removing each character that doesn't match. Removing would decrease the length, that's where "i--" comes into play in my code.