File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Expand file tree Collapse file tree 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)
7373 return true ;
7474
7575 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 ++ )
8077 {
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 ) ;
8982 }
9083 return true ;
9184 }
You can’t perform that action at this time.
0 commit comments