JS | Clean Code (RunTime Beats 100% | Memory Beats 100%)
\n\n# Code\n\n/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number[][]} edges\n * @return {number}\n */\nvar maximumValueSum = function (nums
![Screen Shot 2024-05-19 at 09.45.59.png](https://assets.leetcode.com/users/images/f4977d19-6d92-4334-8e1c-ff5c7a4de959_1716083245.031134.png)\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number[][]} edges\n * @return {number}\n */\nvar maximumValueSum = function (nums, k, edges) {\n    let count = 0;\n    let sum = 0;\n    let minDiff = Infinity;\n    for (let num of nums) {\n        let xorNum = (num ^ k);\n        if (xorNum > num) {\n            count++;\n        }\n        sum += Math.max(xorNum, num);\n        minDiff = Math.min(Math.abs(xorNum - num), minDiff);\n    }\n\n    if (count % 2 === 1) sum -= minDiff;\n\n    return sum;\n};\n```
['JavaScript']