Leetcode Problem 2508. Add Edges to Make Degrees of All Nodes Even
2508. Add Edges to Make Degrees of All Nodes Even
Leetcode Solutions
Even Degree Graph with At Most Two Additional Edges
Create a degree array to count the degree of each node.
Iterate through the edges to fill the degree array and count the number of nodes with odd degrees.
If there are 0 odd degree nodes, return true.
If there is 1 or more than 4 odd degree nodes, return false.
If there are 2 odd degree nodes, check if they are directly connected. If not, return true; otherwise, check for a node that is not connected to either and return true if found.
If there are 4 odd degree nodes, check if you can pair them without any existing edge between the pairs. Return true if possible.