Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc066589

Browse files
add 2917
1 parent149643d commitc066589

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

Lines changed: 1 addition & 0 deletions
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|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder.solutions.thirdthousand;
2+
3+
publicclass_2917 {
4+
publicstaticclassSolution1 {
5+
publicintfindKOr(int[]nums,intk) {
6+
String[]strings =newString[nums.length];
7+
for (inti =0;i <nums.length;i++) {
8+
strings[i] =Integer.toBinaryString(nums[i]);
9+
}
10+
intans =0;
11+
intbase =1;
12+
for (inti =1;i <64;i++) {
13+
intsetBits =0;
14+
for (Stringstr :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+
returnans;
25+
}
26+
}
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder.thirdthousand;
2+
3+
importcom.fishercoder.solutions.thirdthousand._2917;
4+
importorg.junit.jupiter.api.BeforeEach;
5+
importorg.junit.jupiter.api.Test;
6+
7+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
8+
9+
publicclass_2917Test {
10+
privatestatic_2917.Solution1solution1;
11+
12+
@BeforeEach
13+
publicvoidsetup() {
14+
solution1 =new_2917.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(9,solution1.findKOr(newint[]{7,12,9,8,9,15},4));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp