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

Commit4cb33be

Browse files
authored
Added task 2317.
1 parent5e7e50f commit4cb33be

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,7 @@ implementation 'com.github.javadev:leetcode-in-java:1.11'
14851485

14861486
| # | Title | Difficulty | Tag | Time, ms | Time, %
14871487
|------|----------------|-------------|-------------|----------|---------
1488+
| 2317 |[Maximum XOR After Operations](src/main/java/g2301_2400/s2317_maximum_xor_after_operations/Solution.java)| Medium || 1 | 100.00
14881489
| 2316 |[Count Unreachable Pairs of Nodes in an Undirected Graph](src/main/java/g2301_2400/s2316_count_unreachable_pairs_of_nodes_in_an_undirected_graph/Solution.java)| Medium || 32 | 100.00
14891490
| 2315 |[Count Asterisks](src/main/java/g2301_2400/s2315_count_asterisks/Solution.java)| Easy || 1 | 100.00
14901491
| 2312 |[Selling Pieces of Wood](src/main/java/g2301_2400/s2312_selling_pieces_of_wood/Solution.java)| Hard | Backtracking | 78 | 63.64
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packageg2301_2400.s2317_maximum_xor_after_operations;
2+
3+
// #Medium #2022_06_26_Time_1_ms_(100.00%)_Space_53.3_MB_(100.00%)
4+
5+
publicclassSolution {
6+
publicintmaximumXOR(int[]nums) {
7+
intmax =0;
8+
for (intn :nums) {
9+
max |=n;
10+
}
11+
returnmax;
12+
}
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2317\. Maximum XOR After Operations
2+
3+
Medium
4+
5+
You are given a**0-indexed** integer array`nums`. In one operation, select**any** non-negative integer`x` and an index`i`, then**update**`nums[i]` to be equal to`nums[i] AND (nums[i] XOR x)`.
6+
7+
Note that`AND` is the bitwise AND operation and`XOR` is the bitwise XOR operation.
8+
9+
Return_the**maximum** possible bitwise XOR of all elements of_`nums`_after applying the operation**any number** of times_.
10+
11+
**Example 1:**
12+
13+
**Input:** nums =[3,2,4,6]
14+
15+
**Output:** 7
16+
17+
**Explanation:** Apply the operation with x = 4 and i = 3, num[3] = 6 AND (6 XOR 4) = 6 AND 2 = 2.
18+
19+
Now, nums =[3, 2, 4, 2] and the bitwise XOR of all the elements = 3 XOR 2 XOR 4 XOR 2 = 7.
20+
21+
It can be shown that 7 is the maximum possible bitwise XOR.
22+
23+
Note that other operations may be used to achieve a bitwise XOR of 7.
24+
25+
**Example 2:**
26+
27+
**Input:** nums =[1,2,3,9,2]
28+
29+
**Output:** 11
30+
31+
**Explanation:** Apply the operation zero times.
32+
33+
The bitwise XOR of all the elements = 1 XOR 2 XOR 3 XOR 9 XOR 2 = 11.
34+
35+
It can be shown that 11 is the maximum possible bitwise XOR.
36+
37+
**Constraints:**
38+
39+
* <code>1 <= nums.length <= 10<sup>5</sup></code>
40+
* <code>0 <= nums[i] <= 10<sup>8</sup></code>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
packageg2301_2400.s2317_maximum_xor_after_operations;
2+
3+
importstaticorg.hamcrest.CoreMatchers.equalTo;
4+
importstaticorg.hamcrest.MatcherAssert.assertThat;
5+
6+
importorg.junit.jupiter.api.Test;
7+
8+
classSolutionTest {
9+
@Test
10+
voidmaximumXOR() {
11+
assertThat(newSolution().maximumXOR(newint[] {3,2,4,6}),equalTo(7));
12+
}
13+
14+
@Test
15+
voidmaximumXOR2() {
16+
assertThat(newSolution().maximumXOR(newint[] {1,2,3,9,2}),equalTo(11));
17+
}
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp