Skip to content

Commit 9633451

Browse files
committed
feat: add golang solution to lc problem: No.2103
No.2103.Rings and Rods
1 parent 71ff4d8 commit 9633451

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

solution/2100-2199/2103.Rings and Rods/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Solution:
8080
for i in range(1, len(rings), 2):
8181
c = int(rings[i])
8282
mp[c].add(rings[i - 1])
83-
return sum(1 for v in mp.values() if len(v) == 3)
83+
return sum(len(v) == 3 for v in mp.values())
8484
```
8585

8686
### **Java**
@@ -127,9 +127,29 @@ public:
127127
};
128128
```
129129
130-
### **TypeScript**
130+
### **Go**
131+
132+
```go
133+
func countPoints(rings string) int {
134+
mp := make(map[byte]map[byte]bool)
135+
for i := 1; i < len(rings); i += 2 {
136+
c := rings[i]
137+
if len(mp[c]) == 0 {
138+
mp[c] = make(map[byte]bool)
139+
}
140+
mp[c][rings[i-1]] = true
141+
}
142+
ans := 0
143+
for _, v := range mp {
144+
if len(v) == 3 {
145+
ans++
146+
}
147+
}
148+
return ans
149+
}
150+
```
131151

132-
<!-- 这里可写当前语言的特殊实现逻辑 -->
152+
### **TypeScript**
133153

134154
```ts
135155

solution/2100-2199/2103.Rings and Rods/README_EN.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Solution:
7575
for i in range(1, len(rings), 2):
7676
c = int(rings[i])
7777
mp[c].add(rings[i - 1])
78-
return sum(1 for v in mp.values() if len(v) == 3)
78+
return sum(len(v) == 3 for v in mp.values())
7979
```
8080

8181
### **Java**
@@ -120,6 +120,28 @@ public:
120120
};
121121
```
122122
123+
### **Go**
124+
125+
```go
126+
func countPoints(rings string) int {
127+
mp := make(map[byte]map[byte]bool)
128+
for i := 1; i < len(rings); i += 2 {
129+
c := rings[i]
130+
if len(mp[c]) == 0 {
131+
mp[c] = make(map[byte]bool)
132+
}
133+
mp[c][rings[i-1]] = true
134+
}
135+
ans := 0
136+
for _, v := range mp {
137+
if len(v) == 3 {
138+
ans++
139+
}
140+
}
141+
return ans
142+
}
143+
```
144+
123145
### **TypeScript**
124146

125147
```ts
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
func countPoints(rings string) int {
2+
mp := make(map[byte]map[byte]bool)
3+
for i := 1; i < len(rings); i += 2 {
4+
c := rings[i]
5+
if len(mp[c]) == 0 {
6+
mp[c] = make(map[byte]bool)
7+
}
8+
mp[c][rings[i-1]] = true
9+
}
10+
ans := 0
11+
for _, v := range mp {
12+
if len(v) == 3 {
13+
ans++
14+
}
15+
}
16+
return ans
17+
}

solution/2100-2199/2103.Rings and Rods/Solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ def countPoints(self, rings: str) -> int:
44
for i in range(1, len(rings), 2):
55
c = int(rings[i])
66
mp[c].add(rings[i - 1])
7-
return sum(1 for v in mp.values() if len(v) == 3)
7+
return sum(len(v) == 3 for v in mp.values())

0 commit comments

Comments
 (0)