Skip to content

Commit c5935c0

Browse files
authored
Create 3068. Find the Maximum Sum of Node Values1 (#802)
2 parents b3b116d + a4df875 commit c5935c0

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+
class Solution {
2+
public:
3+
long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {
4+
long long ans = 0;
5+
int minLoss = INT_MAX;
6+
int canInc = 0;
7+
8+
for(int i = 0; i < nums.size(); i++){
9+
if(nums[i] > (nums[i]^k)) ans += nums[i];
10+
else {
11+
ans += nums[i]^k;
12+
canInc++;
13+
}
14+
minLoss = min(minLoss,abs(nums[i]-(nums[i]^k)));
15+
}
16+
if(canInc % 2 == 0) return ans;
17+
return ans-minLoss;
18+
}
19+
};

0 commit comments

Comments
 (0)