Skip to content

Commit 88384e8

Browse files
committed
Runtime: 121 ms (Top 6.20%) | Memory: 43.8 MB (Top 29.46%)
1 parent 99fbfc9 commit 88384e8

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1+
// Runtime: 121 ms (Top 6.20%) | Memory: 43.8 MB (Top 29.46%)
12
var MapSum = function() {
2-
this.hashKeys = new Map();
3-
this.hashVals = new Map();
3+
this.hashKeys = new Map();
4+
this.hashVals = new Map();
45
};
56

67
MapSum.prototype.insert = function(key, val) {
7-
let prefix = '';
8-
for (const str of key) {
9-
prefix += str;
10-
const hashKey = this.hashKeys.get(prefix) ?? new Set();
11-
hashKey.add(key);
12-
!this.hashKeys.has(prefix) && this.hashKeys.set(prefix, hashKey);
13-
}
14-
this.hashVals.set(key, val);
8+
let prefix = '';
9+
for (const str of key) {
10+
prefix += str;
11+
const hashKey = this.hashKeys.get(prefix) ?? new Set();
12+
hashKey.add(key);
13+
!this.hashKeys.has(prefix) && this.hashKeys.set(prefix, hashKey);
14+
}
15+
this.hashVals.set(key, val);
1516
};
1617

1718
MapSum.prototype.sum = function(prefix) {
18-
const hashKey = this.hashKeys.get(prefix);
19-
if (!hashKey) return 0;
20-
let sum = 0;
21-
hashKey.forEach(key => sum += this.hashVals.get(key));
22-
return sum;
19+
const hashKey = this.hashKeys.get(prefix);
20+
if (!hashKey) return 0;
21+
let sum = 0;
22+
hashKey.forEach(key => sum += this.hashVals.get(key));
23+
return sum;
2324
};

0 commit comments

Comments
 (0)