diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/3068. Find the Maximum Sum of Node Values.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/3068. Find the Maximum Sum of Node Values.java" new file mode 100644 index 00000000..56e900c4 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/3068. Find the Maximum Sum of Node Values.java" @@ -0,0 +1,25 @@ +class Solution { + public long maximumValueSum(int[] nums, int k, int[][] edges) { + long maxSum = 0; + int count = 0; + int minDiff = Integer.MAX_VALUE; + + for (int num : nums) { + int xorVal = num ^ k; + if (xorVal > num) { + maxSum += xorVal; + count++; + minDiff = Math.min(minDiff, xorVal - num); + } else { + maxSum += num; + minDiff = Math.min(minDiff, num - xorVal); + } + } + + if (count % 2 == 1) { + maxSum -= minDiff; + } + + return maxSum; + } +} \ No newline at end of file