Skip to content

Commit 35b8baa

Browse files
add 3917
1 parent 0dcbf85 commit 35b8baa

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
| 3931 | [Check Adjacent Digit Differences](https://leetcode.com/problems/check-adjacent-digit-differences/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3931.java) | | Easy |
1818
| 3925 | [Concatenate Array With Reverse](https://leetcode.com/problems/concatenate-array-with-reverse/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3925.java) | | Easy |
1919
| 3921 | [Score Validator](https://leetcode.com/problems/score-validator/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3921.java) | | Easy |
20+
| 3917 | [Count Indices With Opposite Parity](https://leetcode.com/problems/count-indices-with-opposite-parity/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3917.java) | | Easy |
2021
| 3913 | [Sort Vowels by Frequency](https://leetcode.com/problems/sort-vowels-by-frequency/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3913.java) | | Easy |
2122
| 3908 | [Valid Digit Number](https://leetcode.com/problems/valid-digit-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3908.java) | | Easy |
2223
| 3701 | [Compute Alternating Sum](https://leetcode.com/problems/compute-alternating-sum/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3701.java) | | Easy |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3917 {
4+
public static class Solution1 {
5+
public int[] countOppositeParity(int[] nums) {
6+
int[] res = new int[nums.length];
7+
for (int i = 0; i < nums.length; i++) {
8+
int score = 0;
9+
for (int j = i + 1; j < nums.length; j++) {
10+
//use exclusive or for two numbers, if they are of different parity, i.e. one is odd, the other is even, then the result of their least significant bit should be 1, then & 1 should be 1
11+
if (((nums[i] ^ nums[j]) & 1) == 1) {
12+
score++;
13+
}
14+
}
15+
res[i] = score;
16+
}
17+
return res;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)