From 7a8bf98c1abdc7fe35936043f7274208ecb81f9f Mon Sep 17 00:00:00 2001 From: BhanuGoel1312 Date: Thu, 1 Feb 2024 22:45:47 +0530 Subject: [PATCH 1/3] Bhanu Java Pr Test --- Bhanu/Hello.java | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Bhanu/Hello.java diff --git a/Bhanu/Hello.java b/Bhanu/Hello.java new file mode 100644 index 0000000..162d14d --- /dev/null +++ b/Bhanu/Hello.java @@ -0,0 +1,99 @@ +public class Hello { + + static class TreeNode { + + int val; + + TreeNode left; + TreeNode right; + + TreeNode() { + + } + + TreeNode(int val) { + + this.val = val; + + } + + TreeNode(int val, TreeNode left, TreeNode right) { + + this.val = val; + this.left = left; + this.right = right; + + } + + } + + static int countPseudoPalindromicPaths = 0; + + private static boolean isPathPalindromic(int[] pathFreq) { + + int numberOfOddFreq = 0; + + for (int idx = 0; idx < 10; ++idx) { + + if (pathFreq[idx] % 2 != 0) { + + ++numberOfOddFreq; + + } + + } + + if (numberOfOddFreq <= 1) { + + return true; + + } + + return false; + + } + + private static void allPaths(TreeNode root, int[] pathFreq) { + + if (root == null) { + + return; + + } + + ++pathFreq[root.val - 1]; + + if (root.left == null && root.right == null) { + + if (isPathPalindromic(pathFreq)) { + + ++countPseudoPalindromicPaths; + + } + + } else { + + allPaths(root.left, pathFreq); + allPaths(root.right, pathFreq); + + } + + --pathFreq[root.val - 1]; + + } + + public int pseudoPalindromicPaths(TreeNode root) { + + int[] pathFreq = new int[9]; + + allPaths(root, pathFreq); + + int count = countPseudoPalindromicPaths; + + countPseudoPalindromicPaths = 0; + + return count; + + } + +} From 09fd45fb5fea59447923406019276a3a443c0ec3 Mon Sep 17 00:00:00 2001 From: BhanuGoel1312 Date: Thu, 1 Feb 2024 22:51:57 +0530 Subject: [PATCH 2/3] Bhanu Hello --- Bhanu/HelloBhanu.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Bhanu/HelloBhanu.java diff --git a/Bhanu/HelloBhanu.java b/Bhanu/HelloBhanu.java new file mode 100644 index 0000000..b628bb5 --- /dev/null +++ b/Bhanu/HelloBhanu.java @@ -0,0 +1,9 @@ +public class HelloBhanu { + + public static void main(String[] args) { + + System.out.println("Hello World"); + + } + +} \ No newline at end of file From 42813d5187aa603cee620fcc438e4b81a1545e0d Mon Sep 17 00:00:00 2001 From: Abhay Chauhan <79973672+thoughtlessnerd@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:52:37 +0530 Subject: [PATCH 3/3] Delete Bhanu/Hello.java --- Bhanu/Hello.java | 99 ------------------------------------------------ 1 file changed, 99 deletions(-) delete mode 100644 Bhanu/Hello.java diff --git a/Bhanu/Hello.java b/Bhanu/Hello.java deleted file mode 100644 index 162d14d..0000000 --- a/Bhanu/Hello.java +++ /dev/null @@ -1,99 +0,0 @@ -public class Hello { - - static class TreeNode { - - int val; - - TreeNode left; - TreeNode right; - - TreeNode() { - - } - - TreeNode(int val) { - - this.val = val; - - } - - TreeNode(int val, TreeNode left, TreeNode right) { - - this.val = val; - this.left = left; - this.right = right; - - } - - } - - static int countPseudoPalindromicPaths = 0; - - private static boolean isPathPalindromic(int[] pathFreq) { - - int numberOfOddFreq = 0; - - for (int idx = 0; idx < 10; ++idx) { - - if (pathFreq[idx] % 2 != 0) { - - ++numberOfOddFreq; - - } - - } - - if (numberOfOddFreq <= 1) { - - return true; - - } - - return false; - - } - - private static void allPaths(TreeNode root, int[] pathFreq) { - - if (root == null) { - - return; - - } - - ++pathFreq[root.val - 1]; - - if (root.left == null && root.right == null) { - - if (isPathPalindromic(pathFreq)) { - - ++countPseudoPalindromicPaths; - - } - - } else { - - allPaths(root.left, pathFreq); - allPaths(root.right, pathFreq); - - } - - --pathFreq[root.val - 1]; - - } - - public int pseudoPalindromicPaths(TreeNode root) { - - int[] pathFreq = new int[9]; - - allPaths(root, pathFreq); - - int count = countPseudoPalindromicPaths; - - countPseudoPalindromicPaths = 0; - - return count; - - } - -}