diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/3068. Find the Maximum Sum of Node Values.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/3068. Find the Maximum Sum of Node Values.py" new file mode 100644 index 00000000..35253603 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/3068. Find the Maximum Sum of Node Values.py" @@ -0,0 +1,21 @@ +class Solution: + def maximumValueSum( + self, nums: list[int], k: int, edges: list[list[int]] + ) -> int: + total = sum(nums) + positive_count = 0 + min_diff = float('inf') + + for num in nums: + diff = (num ^ k) - num + + if diff > 0: + total += diff + positive_count += 1 + + min_diff = min(min_diff, abs(diff)) + + if positive_count % 2 == 1: + total -= min_diff + + return total