File tree 1 file changed +29
-1
lines changed
solution/3000-3099/3068.Find the Maximum Sum of Node Values
1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,35 @@ tags:
117
117
#### C++
118
118
119
119
``` cpp
120
-
120
+ class Solution {
121
+ public:
122
+ long long maximumValueSum(vector<int >& nums, int k,
123
+ vector<vector<int >>& edges) {
124
+ long long totalSum = 0;
125
+ int count = 0;
126
+ int positiveMin = INT_MAX;
127
+ int negativeMax = INT_MIN;
128
+
129
+ for (int nodeValue : nums) {
130
+ int nodeValAfterOperation = nodeValue ^ k;
131
+ totalSum += nodeValue;
132
+ int netChange = nodeValAfterOperation - nodeValue;
133
+
134
+ if (netChange > 0) {
135
+ positiveMin = min(positiveMin, netChange);
136
+ totalSum += netChange;
137
+ count += 1;
138
+ } else {
139
+ negativeMax = max(negativeMax, netChange);
140
+ }
141
+ }
142
+
143
+ if (count % 2 == 0 ) {
144
+ return totalSum;
145
+ }
146
+ return max(totalSum - positiveMin, totalSum + negativeMax);
147
+ }
148
+ };
121
149
```
122
150
123
151
#### Go
You can’t perform that action at this time.
0 commit comments