File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } s
3
+ * @param {string } t
4
+ * @return {boolean }
5
+ */
6
+ var isAnagram = function ( s , t ) {
7
+ if ( s . length !== t . length ) {
8
+ return false
9
+ }
10
+
11
+ let sCharCount = { } ;
12
+
13
+ for ( let i = 0 ; i < s . length ; i ++ ) {
14
+ let sChar = s [ i ] ;
15
+ sCharCount [ sChar ] = sCharCount [ sChar ] + 1 || 1 ;
16
+ }
17
+
18
+ for ( let i = 0 ; i < t . length ; i ++ ) {
19
+ const tChar = t [ i ] ;
20
+ if ( ! sCharCount [ tChar ] ) {
21
+ return false
22
+ } else {
23
+ sCharCount [ tChar ] --
24
+ }
25
+ }
26
+
27
+ return true ;
28
+ } ;
29
+
30
+ // ================================================================================================================================================================
31
+
1
32
/**
2
33
* @param {string } s
3
34
* @param {string } t
You can’t perform that action at this time.
0 commit comments