File tree 1 file changed +5
-12
lines changed
1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change @@ -73,19 +73,12 @@ public static bool IsAnargram(string source, string other)
73
73
return true ;
74
74
75
75
int len = source . Length ;
76
- // Hash set which will contains all the characters present in input source.
77
- var hashSetSourceChars = new HashSet < char > ( ) ;
78
- var hashSetOtherChars = new HashSet < char > ( ) ;
79
- for ( int i = 0 ; i < len ; i ++ )
76
+ for ( int i = 0 ; i < len ; i ++ )
80
77
{
81
- hashSetSourceChars . Add ( source [ i ] ) ;
82
- hashSetOtherChars . Add ( other [ i ] ) ;
83
- }
84
- for ( int i = 0 ; i < len ; i ++ )
85
- {
86
- // Inputs are not Anargram if characers from *other are not present in *source.
87
- if ( ! hashSetSourceChars . Contains ( other [ i ] ) ) return false ;
88
- if ( ! hashSetOtherChars . Contains ( source [ i ] ) ) return false ;
78
+ int index = other . IndexOf ( source [ i ] ) ;
79
+ if ( index == - 1 )
80
+ return false ;
81
+ other . Remove ( index ) ;
89
82
}
90
83
return true ;
91
84
}
You can’t perform that action at this time.
0 commit comments