File tree Expand file tree Collapse file tree 5 files changed +132
-0
lines changed
solution/2100-2199/2176.Count Equal and Divisible Pairs in an Array Expand file tree Collapse file tree 5 files changed +132
-0
lines changed Original file line number Diff line number Diff line change @@ -120,7 +120,54 @@ func countPairs(nums []int, k int) int {
120
120
### ** TypeScript**
121
121
122
122
``` ts
123
+ function countPairs(nums : number [], k : number ): number {
124
+ const n = nums .length ;
125
+ let ans = 0 ;
126
+ for (let i = 0 ; i < n - 1 ; i ++ ) {
127
+ for (let j = i + 1 ; j < n ; j ++ ) {
128
+ if (nums [i ] === nums [j ] && (i * j ) % k === 0 ) {
129
+ ans ++ ;
130
+ }
131
+ }
132
+ }
133
+ return ans ;
134
+ }
135
+ ```
123
136
137
+ ### ** Rust**
138
+
139
+ ``` rust
140
+ impl Solution {
141
+ pub fn count_pairs (nums : Vec <i32 >, k : i32 ) -> i32 {
142
+ let k = k as usize ;
143
+ let n = nums . len ();
144
+ let mut ans = 0 ;
145
+ for i in 0 .. n - 1 {
146
+ for j in i + 1 .. n {
147
+ if nums [i ] == nums [j ] && i * j % k == 0 {
148
+ ans += 1 ;
149
+ }
150
+ }
151
+ }
152
+ ans
153
+ }
154
+ }
155
+ ```
156
+
157
+ ### ** C**
158
+
159
+ ``` c
160
+ int countPairs (int * nums, int numsSize, int k) {
161
+ int ans = 0;
162
+ for (int i = 0; i < numsSize - 1; i++) {
163
+ for (int j = i + 1; j < numsSize; j++) {
164
+ if (nums[ i] == nums[ j] && i * j % k == 0) {
165
+ ans++;
166
+ }
167
+ }
168
+ }
169
+ return ans;
170
+ }
124
171
```
125
172
126
173
### **...**
Original file line number Diff line number Diff line change @@ -110,7 +110,54 @@ func countPairs(nums []int, k int) int {
110
110
### ** TypeScript**
111
111
112
112
``` ts
113
+ function countPairs(nums : number [], k : number ): number {
114
+ const n = nums .length ;
115
+ let ans = 0 ;
116
+ for (let i = 0 ; i < n - 1 ; i ++ ) {
117
+ for (let j = i + 1 ; j < n ; j ++ ) {
118
+ if (nums [i ] === nums [j ] && (i * j ) % k === 0 ) {
119
+ ans ++ ;
120
+ }
121
+ }
122
+ }
123
+ return ans ;
124
+ }
125
+ ```
113
126
127
+ ### ** Rust**
128
+
129
+ ``` rust
130
+ impl Solution {
131
+ pub fn count_pairs (nums : Vec <i32 >, k : i32 ) -> i32 {
132
+ let k = k as usize ;
133
+ let n = nums . len ();
134
+ let mut ans = 0 ;
135
+ for i in 0 .. n - 1 {
136
+ for j in i + 1 .. n {
137
+ if nums [i ] == nums [j ] && i * j % k == 0 {
138
+ ans += 1 ;
139
+ }
140
+ }
141
+ }
142
+ ans
143
+ }
144
+ }
145
+ ```
146
+
147
+ ### ** C**
148
+
149
+ ``` c
150
+ int countPairs (int * nums, int numsSize, int k) {
151
+ int ans = 0;
152
+ for (int i = 0; i < numsSize - 1; i++) {
153
+ for (int j = i + 1; j < numsSize; j++) {
154
+ if (nums[ i] == nums[ j] && i * j % k == 0) {
155
+ ans++;
156
+ }
157
+ }
158
+ }
159
+ return ans;
160
+ }
114
161
```
115
162
116
163
### **...**
Original file line number Diff line number Diff line change
1
+ int countPairs (int * nums , int numsSize , int k ) {
2
+ int ans = 0 ;
3
+ for (int i = 0 ; i < numsSize - 1 ; i ++ ) {
4
+ for (int j = i + 1 ; j < numsSize ; j ++ ) {
5
+ if (nums [i ] == nums [j ] && i * j % k == 0 ) {
6
+ ans ++ ;
7
+ }
8
+ }
9
+ }
10
+ return ans ;
11
+ }
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn count_pairs ( nums : Vec < i32 > , k : i32 ) -> i32 {
3
+ let k = k as usize ;
4
+ let n = nums. len ( ) ;
5
+ let mut ans = 0 ;
6
+ for i in 0 ..n - 1 {
7
+ for j in i + 1 ..n {
8
+ if nums[ i] == nums[ j] && i * j % k == 0 {
9
+ ans += 1 ;
10
+ }
11
+ }
12
+ }
13
+ ans
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ function countPairs ( nums : number [ ] , k : number ) : number {
2
+ const n = nums . length ;
3
+ let ans = 0 ;
4
+ for ( let i = 0 ; i < n - 1 ; i ++ ) {
5
+ for ( let j = i + 1 ; j < n ; j ++ ) {
6
+ if ( nums [ i ] === nums [ j ] && ( i * j ) % k === 0 ) {
7
+ ans ++ ;
8
+ }
9
+ }
10
+ }
11
+ return ans ;
12
+ }
You can’t perform that action at this time.
0 commit comments