Skip to content

Commit c066589

Browse files
add 2917
1 parent 149643d commit c066589

File tree

3 files changed

+50
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+50
-0
lines changed

paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2965.java) | | Easy |
77
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2942.java) | | Easy |
88
| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2937.java) | | Easy |
9+
| 2917 | [Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2917.java) | | Easy |
910
| 2913 | [Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2913.java) | | Easy |
1011
| 2908 | [Minimum Sum of Mountain Triplets I](https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2908.java) | | Easy |
1112
| 2903 | [Find Indices With Index and Value Difference I](https://leetcode.com/problems/find-indices-with-index-and-value-difference-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2903.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2917 {
4+
public static class Solution1 {
5+
public int findKOr(int[] nums, int k) {
6+
String[] strings = new String[nums.length];
7+
for (int i = 0; i < nums.length; i++) {
8+
strings[i] = Integer.toBinaryString(nums[i]);
9+
}
10+
int ans = 0;
11+
int base = 1;
12+
for (int i = 1; i < 64; i++) {
13+
int setBits = 0;
14+
for (String str : strings) {
15+
if (str.length() >= i) {
16+
setBits += Integer.parseInt(str.charAt(str.length() - i) + "");
17+
}
18+
}
19+
if (setBits >= k) {
20+
ans += base;
21+
}
22+
base *= 2;
23+
}
24+
return ans;
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2917;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _2917Test {
10+
private static _2917.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2917.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(9, solution1.findKOr(new int[]{7, 12, 9, 8, 9, 15}, 4));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)