File tree Expand file tree Collapse file tree 4 files changed +64
-5
lines changed
solution/2100-2199/2103.Rings and Rods Expand file tree Collapse file tree 4 files changed +64
-5
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ class Solution:
80
80
for i in range (1 , len (rings), 2 ):
81
81
c = int (rings[i])
82
82
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())
84
84
```
85
85
86
86
### ** Java**
@@ -127,9 +127,29 @@ public:
127
127
};
128
128
```
129
129
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
+ ```
131
151
132
- <!-- 这里可写当前语言的特殊实现逻辑 -->
152
+ ### ** TypeScript **
133
153
134
154
``` ts
135
155
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ class Solution:
75
75
for i in range (1 , len (rings), 2 ):
76
76
c = int (rings[i])
77
77
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())
79
79
```
80
80
81
81
### ** Java**
@@ -120,6 +120,28 @@ public:
120
120
};
121
121
```
122
122
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
+
123
145
### ** TypeScript**
124
146
125
147
``` ts
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -4,4 +4,4 @@ def countPoints(self, rings: str) -> int:
4
4
for i in range (1 , len (rings ), 2 ):
5
5
c = int (rings [i ])
6
6
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 ())
You can’t perform that action at this time.
0 commit comments