Skip to content

Commit a7ba978

Browse files
authored
Create 2103-rings-and-rods.js
1 parent e642e87 commit a7ba978

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2103-rings-and-rods.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {string} rings
3+
* @return {number}
4+
*/
5+
const countPoints = function(rings) {
6+
const hash = {}
7+
8+
for(let i = 0, n = rings.length; i < n; i+=2) {
9+
const ch = rings[i], num = +rings[i + 1]
10+
if(hash[num] == null) hash[num] = new Set()
11+
hash[num].add(ch)
12+
}
13+
14+
15+
16+
let res = 0
17+
Object.keys(hash).forEach(k => {
18+
if(hash[k].size === 3) res++
19+
})
20+
21+
return res
22+
};

0 commit comments

Comments
 (0)