A vertex cover of an undirected graph is a subset of its vertices such that for every edge (u, v) of the graph, either ‘u’ or ‘v’ is in vertex cover.

Given a binary tree with **N** nodes, find and return the minimum of nodes in its vertex cover.

**Input Format:**

```
The first and the only argument has a pointer to the root node of the binary tree.
```

**Output Format**

```
Return an integer, representing the answer as described in the question.
```

**Constraints**

```
1 <= N <= 1e5
```

**For Example:**

```
Input 1:
1
/ \
15 2
Output 1:
1
Explanation 1:
[1] is enough to be the vertex cover of the tree.
Input 2:
1
Output 2:
0
Explanation 2:
[] is enough to be the vertex cover of the tree.
Input 3:
9
/ \
6 17
/ \
23 7
Output 3:
2
Explanation 3:
[9, 6] is enough to be the vertex cover of the tree.
```

NOTE:You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.

Sign Up

to access hints and editorial solutions for**Vertex Cover Problem**

to access hints and editorial solutions for

Loading...