How to Find out Given 2 String is
anagram or Not
Anagram string are those
string which character are same in no of sequence
For Example
Required input and output
Input: silent
Output: listen
Output: listen
Input: Ganga
Output: agnga
Output: agnga
Input: Yahoo
Output: hooya
Output: hooya
Solution:
You can achieve this by many ways
1.
Using of char Array then
sort the array & compare the array char value
Step 1:
public bool strignAnagram(String str1, String S2)
{
char[] Str1Arr= str1.ToCharArray();
char[] Str2Arr = S2.ToCharArray();
Array.Sort(Str1Arr);
Array.Sort(Str2Arr);
for (int i = 0; i <= str1.Length - 1; i++)
{
if (Str1Arr[i] != Str2Arr[i])
{
return false;
}
}
return true;
}
In Main Function
Console.WriteLine("STring Anagram = "+ obj.strignAnagram("silent", "tnelis"));
No comments:
Post a Comment