Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int conta_occ(int V[], int len, int x, int i = 0) {
- if (len == i) return 0;
- if (V[i] == x) return 1 + conta_occ(V, len, x, i + 1);
- return conta_occ(V, len, x, i + 1);
- }
- bool is_redundant(int V[], int len, int i = 0) {
- if (len == i) return true;
- if (conta_occ(V, len, V[i]) != 2) {
- return false;
- }
- return is_redundant(V, len, i + 1);
- }
- int main() {
- int arr[] = {1, 1, 4, 4, 5, 3, 3, 5 };
- cout << is_redundant(arr, sizeof(arr) / sizeof(arr[0]));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement