File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 70
70
| 231| [ 2 的幂] ( https://leetcode.cn/problems/power-of-two/ ) | [ JavaScript] ( ./algorithms/power-of-two.js ) | Easy|
71
71
| 234| [ 回文链表] ( https://leetcode-cn.com/problems/palindrome-linked-list/ ) | [ JavaScript] ( ./algorithms/palindrome-linked-list.js ) | Easy|
72
72
| 237| [ 删除链表中的节点] ( https://leetcode-cn.com/problems/delete-node-in-a-linked-list/ ) | [ JavaScript] ( ./algorithms/delete-node-in-a-linked-list.js ) | Easy|
73
+ | 242| [ 有效的字母异位词] ( https://leetcode.cn/problems/valid-anagram/ ) | [ JavaScript] ( ./algorithms/valid-anagram.js ) | Easy|
73
74
| 257| [ 二叉树的所有路径] ( https://leetcode.cn/problems/binary-tree-paths/ ) | [ JavaScript] ( ./algorithms/binary-tree-paths.js ) | Easy|
74
75
| 283| [ 移动零] ( https://leetcode.cn/problems/move-zeroes/ ) | [ JavaScript] ( ./algorithms/move-zeroes.js ) | Easy|
75
76
| 303| [ 区域和检索 - 数组不可变] ( https://leetcode.cn/problems/range-sum-query-immutable/ ) | [ JavaScript] ( ./algorithms/range-sum-query-immutable.js ) | Easy|
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
+ // 数组哈希计数
8
+ const countArr = Array ( 26 ) . fill ( 0 ) ;
9
+
10
+ if ( s . length !== t . length ) {
11
+ return false ;
12
+ }
13
+
14
+ for ( let char of s ) {
15
+ const index = char . charCodeAt ( ) - "a" . charCodeAt ( ) ;
16
+ countArr [ index ] ++ ;
17
+ }
18
+
19
+ for ( let char of t ) {
20
+ const index = char . charCodeAt ( ) - "a" . charCodeAt ( ) ;
21
+ countArr [ index ] -- ;
22
+ if ( countArr [ index ] < 0 ) {
23
+ return false ;
24
+ }
25
+ }
26
+
27
+ return true ;
28
+ } ;
You can’t perform that action at this time.
0 commit comments