Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int conta(s A) {
- int conta = 0;
- boolean f = checkUnival(A,A.val);
- if (f) {
- conta++
- }
- if (A.left != null) {
- conta += conta(A.left);
- }
- if (A.right != null) {
- conta += conta(A.right);
- }
- return conta;
- }
- public static boolean checkUnival(s A, int i) {
- if (A.left == null && A.right == null && A.val == i) {
- return true;
- }
- if (A.val == i) {
- boolean checkLeft = true;
- boolean checkRight = true;
- if (A.left != null) {
- checkLeft = checkUnival(A.left, i);
- }
- if (A.right != null) {
- checkLeft = checkUnival(A.left, i);
- }
- return checkLeft && checkRight;
- }
- else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement