File tree 5 files changed +111
-0
lines changed
solution/1500-1599/1512.Number of Good Pairs
5 files changed +111
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,48 @@ func numIdenticalPairs(nums []int) int {
114
114
}
115
115
```
116
116
117
+ ### ** TypeScript**
118
+
119
+ ``` ts
120
+ function numIdenticalPairs(nums : number []): number {
121
+ const count = new Array (101 ).fill (0 );
122
+ let ans = 0 ;
123
+ for (const num of nums ) {
124
+ ans += count [num ]++ ;
125
+ }
126
+ return ans ;
127
+ }
128
+ ```
129
+
130
+ ### ** Rust**
131
+
132
+ ``` rust
133
+ impl Solution {
134
+ pub fn num_identical_pairs (nums : Vec <i32 >) -> i32 {
135
+ let mut count = [0 ; 101 ];
136
+ let mut ans = 0 ;
137
+ for & num in nums . iter () {
138
+ ans += count [num as usize ];
139
+ count [num as usize ] += 1 ;
140
+ }
141
+ ans
142
+ }
143
+ }
144
+ ```
145
+
146
+ ### ** C**
147
+
148
+ ``` c
149
+ int numIdenticalPairs (int * nums, int numsSize) {
150
+ int count[ 101] = {0};
151
+ int ans = 0;
152
+ for (int i = 0; i < numsSize; i++) {
153
+ ans += count[ nums[ i]] ++;
154
+ }
155
+ return ans;
156
+ }
157
+ ```
158
+
117
159
### **...**
118
160
119
161
```
Original file line number Diff line number Diff line change @@ -106,6 +106,48 @@ func numIdenticalPairs(nums []int) int {
106
106
}
107
107
```
108
108
109
+ ### ** TypeScript**
110
+
111
+ ``` ts
112
+ function numIdenticalPairs(nums : number []): number {
113
+ const count = new Array (101 ).fill (0 );
114
+ let ans = 0 ;
115
+ for (const num of nums ) {
116
+ ans += count [num ]++ ;
117
+ }
118
+ return ans ;
119
+ }
120
+ ```
121
+
122
+ ### ** Rust**
123
+
124
+ ``` rust
125
+ impl Solution {
126
+ pub fn num_identical_pairs (nums : Vec <i32 >) -> i32 {
127
+ let mut count = [0 ; 101 ];
128
+ let mut ans = 0 ;
129
+ for & num in nums . iter () {
130
+ ans += count [num as usize ];
131
+ count [num as usize ] += 1 ;
132
+ }
133
+ ans
134
+ }
135
+ }
136
+ ```
137
+
138
+ ### ** C**
139
+
140
+ ``` c
141
+ int numIdenticalPairs (int * nums, int numsSize) {
142
+ int count[ 101] = {0};
143
+ int ans = 0;
144
+ for (int i = 0; i < numsSize; i++) {
145
+ ans += count[ nums[ i]] ++;
146
+ }
147
+ return ans;
148
+ }
149
+ ```
150
+
109
151
### **...**
110
152
111
153
```
Original file line number Diff line number Diff line change
1
+ int numIdenticalPairs (int * nums , int numsSize ) {
2
+ int count [101 ] = {0 };
3
+ int ans = 0 ;
4
+ for (int i = 0 ; i < numsSize ; i ++ ) {
5
+ ans += count [nums [i ]]++ ;
6
+ }
7
+ return ans ;
8
+ }
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn num_identical_pairs ( nums : Vec < i32 > ) -> i32 {
3
+ let mut count = [ 0 ; 101 ] ;
4
+ let mut ans = 0 ;
5
+ for & num in nums. iter ( ) {
6
+ ans += count[ num as usize ] ;
7
+ count[ num as usize ] += 1 ;
8
+ }
9
+ ans
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ function numIdenticalPairs ( nums : number [ ] ) : number {
2
+ const count = new Array ( 101 ) . fill ( 0 ) ;
3
+ let ans = 0 ;
4
+ for ( const num of nums ) {
5
+ ans += count [ num ] ++ ;
6
+ }
7
+ return ans ;
8
+ }
You can’t perform that action at this time.
0 commit comments