This is from LeetCode - Valid Anagram
Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Input: s = "anagram", t = "nagaram"
Output: true
Example 2:
You may assume the string contains only lowercase alphabets.
Follow up: What if the inputs contain unicode characters? How would you adapt your solution to such case?
I don't understand these code below
- result1[s.charCodeAt(i) - 97]++; --> what does ++ mean?
- result2.length = 26; --> what does 26 stand for?
- result2.fill(0); --> why does fill it with 0?
Please advise!
var isAnagram = function(s,t) {
if (s.length !== t.length)
result false;
const result1 = [];
result1.length = 26;
result1.fill(0);
const result2 = [];
result2.length = 26;
result2.fill(0);
for (let i = 0; i < s.length; i++) {
result1[s.charCodeAt(i) - 97]++;
result2[t.charCodeAt(i) - 97]++;
}
for (let i = 0; i < result1.length; i++) {
if (result1[i] !== result2[i]) {
return false;
}
}
return true;
};