Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit b948423

Browse files
authored
Create find-the-maximum-sum-of-node-values.cs
1 parent 6b8ebbc commit b948423

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** Time: O(n) **/
2+
3+
public class Solution {
4+
public long MaximumValueSum(int[] nums, int k, int[][] edges)
5+
{
6+
long result = 0;
7+
int diff = int.MaxValue;
8+
int parity = 0;
9+
10+
foreach (var x in nums) {
11+
var y = x ^ k;
12+
result += Math.Max(x, y);
13+
parity ^= x < y ? 1 : 0;
14+
diff = Math.Min(diff, Math.Abs(x - y));
15+
}
16+
17+
return result - parity * diff;
18+
}
19+
}

0 commit comments

Comments
 (0)