diff --git a/readme.md b/readme.md index 38340c9..2040419 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,5 @@ -# 算法demo +# 算法练习 ### 20. 有效的括号 ### 2. 两数相加 +### 1006. 笨阶乘 diff --git a/src/main/java/com/fancv/leetCode/LinkedList/DeleteDuplicates.java b/src/main/java/com/fancv/leetCode/LinkedList/DeleteDuplicates.java new file mode 100644 index 0000000..0e2d00e --- /dev/null +++ b/src/main/java/com/fancv/leetCode/LinkedList/DeleteDuplicates.java @@ -0,0 +1,54 @@ +package com.fancv.leetCode.LinkedList; + +/** + * @author hamish-wu + */ +public class DeleteDuplicates { + + public static void main(String[] args) { + + ListNode a = new ListNode(4, null); + ListNode b = new ListNode(3, a); + ListNode c = new ListNode(2, b); + ListNode d = new ListNode(1, c); + ListNode e = new ListNode(1, d); + + ListNode result = deleteDuplicates(e); + + /* ListNode a1 = new ListNode(4, null); + ListNode b1 = new ListNode(3, a1); + ListNode c1 = new ListNode(2, b1);*/ + ListNode d1 = new ListNode(1, null); + ListNode e1 = new ListNode(1, d1); + ListNode resultq = deleteDuplicates(e1); + System.out.println(); + + } + + /** + * 递归思想 + * 1. 1 1 1 2 3 4 + * 2. 1 + * 3. 1 2 3 3 4 4 + * + * @param head + * @return + */ + public static ListNode deleteDuplicates(ListNode head) { + if (head == null || head.next == null) { + return head; + } + ListNode sail = head.next; + if (head.val == sail.val) { + while (sail!= null && head.val == sail.val) { + sail = sail.next; + } + head = deleteDuplicates(sail); + } else { + head.next = deleteDuplicates(sail); + } + + return head; + + } +} diff --git a/src/main/java/com/fancv/leetCode/LinkedList/ListNode.java b/src/main/java/com/fancv/leetCode/LinkedList/ListNode.java new file mode 100644 index 0000000..82cd275 --- /dev/null +++ b/src/main/java/com/fancv/leetCode/LinkedList/ListNode.java @@ -0,0 +1,24 @@ +package com.fancv.leetCode.LinkedList; + +/** + * leetCode node + * + * @author hamish-wu + */ +public class ListNode { + + int val; + ListNode next; + + ListNode() { + } + + ListNode(int val) { + this.val = val; + } + + ListNode(int val, ListNode next) { + this.val = val; + this.next = next; + } +} diff --git a/src/main/java/com/fancv/leetCode/LinkedList/RemoveNLinkedList.java b/src/main/java/com/fancv/leetCode/LinkedList/RemoveNLinkedList.java index bf1e632..fef9232 100644 --- a/src/main/java/com/fancv/leetCode/LinkedList/RemoveNLinkedList.java +++ b/src/main/java/com/fancv/leetCode/LinkedList/RemoveNLinkedList.java @@ -8,16 +8,16 @@ public class RemoveNLinkedList { public static void main(String[] args) { - ListNode a = new ListNode(9, null); - ListNode b = new ListNode(9, a); - ListNode c = new ListNode(9, null); - ListNode d = new ListNode(9, c); - ListNode e = new ListNode(9, d); + ListNode a = new ListNode(12, null); + ListNode b = new ListNode(5, null); + ListNode c = new ListNode(4, null); + ListNode d = new ListNode(3, c); + ListNode e = new ListNode(1, d); /*removeNthFromEnd(e, 5); System.out.println("结束");*/ - addTwoNumbers(e, b); + mergeTwoLists( b,e); } public static ListNode removeNthFromEnd(ListNode head, int n) { @@ -114,22 +114,69 @@ static ListNode addTwoNumbers(ListNode l1, ListNode l2) { } -} + /** + * 合并两个有序链表 + * + * @param l1 + * @param l2 + * @return + */ + public static ListNode mergeTwoLists(ListNode l1, ListNode l2) { + + //头节点 + ListNode head1 = null; + //新节点尾部节点 + ListNode head2 = null; + //遍历节点 + ListNode sail = null; + /** + * 链表有空的情况 + */ + if (l1 == null && l2 != null) { + return l2; + } + if (l2 == null && l1 != null) { + return l1; + } + if (l1 == null && l2 == null) { + return l1; + } +/** + *选择l1遍历 + */ + boolean tail = false; + if (l1.val >= l2.val) { + head1 = l2; + head2 = l1; + sail = l1; + tail = true; + } else { + head1 = l1; + head2 = l2; + sail = l2; + } -class ListNode { - int val; - ListNode next; + while (head1 != null && head2 != null) { + if (head1.next != null && head1.next.val <= sail.val) { + head1 = head1.next; + } else { + sail = head1.next; + head1.next = head2; + head1 = head1.next; + head2 = sail; + } + } - ListNode() { - } + if (tail) { + return l2; + } else { + return l1; + } - ListNode(int val) { - this.val = val; } - ListNode(int val, ListNode next) { - this.val = val; - this.next = next; - } + } + + diff --git a/src/main/java/com/fancv/leetCode/LinkedList/deleteDuplicatesOne.java b/src/main/java/com/fancv/leetCode/LinkedList/deleteDuplicatesOne.java new file mode 100644 index 0000000..18e992c --- /dev/null +++ b/src/main/java/com/fancv/leetCode/LinkedList/deleteDuplicatesOne.java @@ -0,0 +1,39 @@ +package com.fancv.leetCode.LinkedList; + +public class deleteDuplicatesOne { + + public static void main(String[] args) { + ListNode a = new ListNode(4, null); + ListNode b = new ListNode(2, a); + ListNode c = new ListNode(2, b); + ListNode d = new ListNode(2, c); + ListNode e = new ListNode(1, d); + + ListNode result = deleteDuplicates(e); + System.out.println(result.val); + } + + + /** + * 删除链表中重复元素 回调 + * 1 1 2 3 3 + * + * @param head + * @return + */ + public static ListNode deleteDuplicates(ListNode head) { + if (head == null || head.next == null) { + return head; + } + ListNode sail = head.next; + if (head.val == sail.val) { + while (sail != null && head.val == sail.val) { + sail = sail.next; + } + } + head.next = deleteDuplicates(sail); + + return head; + } + +} diff --git a/src/main/java/com/fancv/leetCode/LinkedList/rotateRight.java b/src/main/java/com/fancv/leetCode/LinkedList/rotateRight.java new file mode 100644 index 0000000..6ff7fe7 --- /dev/null +++ b/src/main/java/com/fancv/leetCode/LinkedList/rotateRight.java @@ -0,0 +1,51 @@ +package com.fancv.leetCode.LinkedList; + +public class rotateRight { + + public static void main(String[] args) { + /* ListNode a = new ListNode(5, null); + ListNode b = new ListNode(4, a);*/ + ListNode c = new ListNode(3, null); + ListNode d = new ListNode(2, c); + ListNode e = new ListNode(1, d); + rotateRight(e, 200000000); + System.out.println(); + } + + /** + * + * + * @param head + * @param k + * @return + */ + public static ListNode rotateRight(ListNode head, int k) { + + + if (head == null || k == 0) { + return head; + } + ListNode sail = head; + int len = 1; + while (sail.next != null) { + len++; + sail = sail.next; + } + + ListNode tail = null; + //循环节点 + tail = sail; + sail.next = head; + sail = head; + //得到循环的次数 + int loop = len - (k % len); + + for (int i = 0; i < loop; i++) { + sail = sail.next; + tail = tail.next; + } + tail.next = null; + + return sail; + } +} diff --git a/src/main/java/com/fancv/leetCode/arrays/MyArrays.java b/src/main/java/com/fancv/leetCode/arrays/MyArrays.java new file mode 100644 index 0000000..9b4fdbb --- /dev/null +++ b/src/main/java/com/fancv/leetCode/arrays/MyArrays.java @@ -0,0 +1,168 @@ +package com.fancv.leetCode.arrays; + +import java.util.*; + +public class MyArrays { + public static void main(String[] args) { + int[] rains = {1, 1, 1, 2, 2, 3, 1, 4, 6, 7}; + int[] b = {-1, 1, 2, 2}; + int[] c = {1, 2, 1, 1, 2, 2, 3, 3, 3}; + System.out.println(subsetsWithDup(b)); + } + + /** + * 避免洪水 + * + * @param rains + * @return + */ + public static int[] avoidFlood(int[] rains) { + int ans[] = new int[rains.length]; + Map r = new HashMap<>(); + //存储可以 rains[i] == 0 的索引位置(这里使用 TreeSet 是为了方便查找 适合 排空湖泊 的索引天数) + TreeSet set = new TreeSet<>(); + + for (int i = 0; i < rains.length; i++) { + if (rains[i] > 0) { + if (r.containsKey(rains[i])) { + //查出第几天哪个池塘下过雨 + int reained = r.get(rains[i]); + Integer zeroIdx = set.higher(reained); + if (zeroIdx == null) { + int a[] = {}; + return a; + } + ans[zeroIdx] = rains[i]; + set.remove(zeroIdx); + } + r.put(rains[i], i); + ans[i] = -1; + } else { + set.add(i); + } + } + + for (int i = 0; i < ans.length; i++) { + if (ans[i] == 0) { + ans[i] = 1; + } + } + return ans; + } + + /** + * 获取获胜者 + *

+ * 1.假设 winner 从 index 0 开始 + * 2.比较之后 j>i+1 是否符合条件 + * 4.若比较过程中 j< arr.lenght-1 计算循环值,每次计算 + * 5.如果 循环一轮之后 无论k 多大 均返回 arr[i] 值 + * + * @param arr + * @param k + * @return + */ + public static int getWinner(int[] arr, int k) { + int winner = 0; + int tempk = 0; + for (int i = 0; i < arr.length; i++) { + winner = arr[i]; + for (int j = i + 1; j < 2 * arr.length; j++) { + if (j >= arr.length) { + j = j - arr.length; + } + if (i == j) { + continue; + } + if (arr[j] < winner) { + tempk++; + } else { + winner = arr[j]; + tempk = 1; + } + if (tempk == k || tempk >= arr.length - 1) { + return winner; + } + + } + + } + return winner; + + } + + /** + * 1.计算数组所有不重复的子集 + * 输入:nums = [1,1,1,1,2] + * 输出:[[],[1],[1,1],[1,1,1],[1,1,1,1],[1,1,1,1,2]] + * 输入:nums = [1,1,2,2] + * 输出:[[],[1],[1,1],[1,1,2],[1,1,2,2],[1,2][1,2,2][2,2][2]] + *

+ * 反思, + * 1.计算子集的算法不对,遗漏很多子集 + * 2.去重算法不对 + *

+ * nums=[-1,1,1,2] + * 子集 [-1] [-1,1],[-1,1,1][-1,1,1,2][-1,1][-1,1,2][1][1,1][1,1,2][1,2][2] + * + * @param nums + * @return + */ + public static List> subsetsWithDup(int[] nums) { + Arrays.sort(nums); + List> result = new ArrayList<>(); + int len = nums.length; + List list = new ArrayList<>(); + /** + * 1.外层循环 2的len 次方 + * C 0/4 + C 1/4 +C2/4+C3/4 +C4/4 + * 1 + 4+ 6+ 4+1=16 + * + */ + for (int i = 0; i < (1 << len); ++i) { + list.clear(); + /** + * 2.内层循环j 0 && (1 << (j - 1) & i) == 0 && nums[j] == nums[j - 1]) { + tag = false; + break; + } + list.add(nums[j]); + } + } + if (tag) { + result.add(new ArrayList<>(list)); + } + + } + return result; + + } + +} + +class Solution { + List> result = new ArrayList<>(); + public List> subsets(int[] nums) { + List temp = new ArrayList<>(); + int len = nums.length; + // 1 外部循环2的len 次方循环 + for (int loop = 0; loop < (1 << len); loop++) { + temp.clear(); + // 内部循环 len + for (int j = 0; j < len; j++) { + //3 位运算判断是否子集 + if ((loop & (1 << j)) != 0) { + temp.add(nums[j]); + } + } + result.add(new ArrayList<>(temp)); + } + return result; + } +} diff --git a/src/main/java/com/fancv/leetCode/mathematics/FactorialClumsy.java b/src/main/java/com/fancv/leetCode/mathematics/FactorialClumsy.java new file mode 100644 index 0000000..c37b8a3 --- /dev/null +++ b/src/main/java/com/fancv/leetCode/mathematics/FactorialClumsy.java @@ -0,0 +1,73 @@ +package com.fancv.leetCode.mathematics; + +/** + * @author hamish-wu + */ +public class FactorialClumsy { + + + public static void main(String[] args) { + + System.out.println(clumsy(4)); + } + + /** + * 通常,正整数 n 的阶乘是所有小于或等于 n 的正整数的乘积。例如,factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1。 + *

+ * 相反,我们设计了一个笨阶乘 clumsy:在整数的递减序列中,我们以一个固定顺序的操作符序列来依次替换原有的乘法操作符:乘法(*),除法(/),加法(+)和减法(-)。 + *

+ * 例如,clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1。然而,这些运算仍然使用通常的算术运算顺序:我们在任何加、减步骤之前执行所有的乘法和除法步骤,并且按从左到右处理乘法和除法步骤。 + *

+ * 另外,我们使用的除法是地板除法(floor division),所以 10 * 9 / 8 等于 11。这保证结果是一个整数。 + *

+ * 实现上面定义的笨函数:给定一个整数 N,它返回 N 的笨阶乘。 + *

+ *   + * 来源:力扣(LeetCode) + * 链接:https://leetcode-cn.com/problems/clumsy-factorial + * 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 + * + * @param N + * @return + */ + public static int clumsy(int N) { + int result = 0; + boolean b = false; + for (int m = N; m > 0; m = m - 4) { + result = result + threeNum(m, b); + b = true; + } + + + return result; + } + + /** + * 四个数字一组计算 + * + * @param a + * @param b + * @return + */ + public static int threeNum(int a, boolean b) { + int temp = 0; + if (a > 3) { + temp = a * (a - 1) / (a - 2); + if (b) { + return (a - 3) - temp; + } else { + return temp + a - 3; + } + } else { + if (a == 1 || a == 2) { + temp = a; + } else { + temp = 6; + } + } + if (b) { + temp = -temp; + } + return temp; + } +} diff --git a/src/main/java/com/fancv/leetCode/mathematics/MathArray.java b/src/main/java/com/fancv/leetCode/mathematics/MathArray.java new file mode 100644 index 0000000..aace844 --- /dev/null +++ b/src/main/java/com/fancv/leetCode/mathematics/MathArray.java @@ -0,0 +1,102 @@ +package com.fancv.leetCode.mathematics; + +import java.util.Arrays; + +/** + * @author hamish-wu + */ +public class MathArray { + + + public static void main(String[] args) { + + + int a[] = {1, 1, 1, 2, 3, 10, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 7, 8, 9, 10, 11, 12, 13, 14}; + int b[] = {2, 1, 2, 2, 3, 1, 0, 0, 9, 5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 3}; + int c[] = {1, 3, 2, 2, 10, 4, 2, 3, 5, 9}; + int d[] = {1, 2, 3, 1,2,3}; + + + System.out.println(findLengthOfShortestSubarray(a)); + System.out.println(findLengthOfShortestSubarray(b)); + System.out.println(findLengthOfShortestSubarray(c)); + System.out.println(containsNearbyDuplicate(d, 2)); + + } + + public int maximumGap(int[] nums) { + + //1.排序 + Arrays.sort(nums); + + //2.遍历元素,计算相邻元素差值 最大 + + + return 0; + } + + /** + * [1,12,3,10,4,2,3,5] 非递减 + *

+ * 1.特殊情况 + * 2.循环遍历 i + * + * @param arr + * @return + */ + public static int findLengthOfShortestSubarray(int[] arr) { + int r = 0; + int len = arr.length; + int tail = -1; + //1.判断空 和length 为1 的情况 + if (arr == null || len == 1) { + return r; + } + // 1.循环遍历 + int temp = -1; + for (int i = 0; i < len; i++) { + //2.相等后移 + if (temp < 0) { + temp = arr[i]; + } + if (arr[i] == temp) { + continue; + } + int head = -1; + int sum = 0; + int min = -1; + for (int j = i + 1; j < len; j++) { + if (arr[j] < temp && arr[j] > min) { + if (head < 0) { + head = j; + } + sum++; + } + } + if (head < sum) { + r = r + head; + } else { + r = r + sum; + + } + + + } + + return r; + } + + public static boolean containsNearbyDuplicate(int[] nums, int k) { + for (int i = 0; i < nums.length; i++) { + int j = i+1; + for (; j - i <= k&&j 2) { + return true; + } + } else { + s = 0; + } + + + } + return false; + + + } + + /** + * 丑数,数字 2 3 5 乘积 + * + * @param n + * @return + */ + public static boolean isUgly(int n) { + boolean r = false; + if (n == 0) { + return r; + } + //1.偶数 + if (n % 2 == 0) { + n = n / 2; + if (n == 1) { + r = true; + } else { + return isUgly(n); + } + } + //2.奇数 3的倍数 + else if (n % 3 == 0) { + n = n / 3; + if (n == 1) { + r = true; + } else { + return isUgly(n); + } + + } else if (n % 5 == 0) { + n = n / 5; + if (n == 1) { + r = true; + } else { + return isUgly(n); + } + + } + if (n == 1) { + r = true; + } + return r; + } + + /** + * 丑数,数字 2 3 5 乘积 + * + * @param n + * @return + */ + public boolean isUgly2(int n) { + boolean r = false; + //1.偶数 + while (n % 2 == 0) { + n = n / 2; + } + //2.奇数 3的倍数 + while (n % 3 == 0) { + n = n / 3; + } + while (n % 5 == 0) { + n = n / 5; + } + if (n == 1) { + r = true; + } + return r; + } + + /** + * 第N 个丑数 笨办法 + * + * @param n + * @return + */ + public static int nthUglyNumber(int n) { + int i = 1; + int temp = 0; + if (n > 200) { + i = 16200; + temp = 199; + } else if (n > 400) { + i = 311040; + temp = 399; + } else if (n > 800) { + i = 12754584; + temp = 799; + } else if (n > 1200) { + i = 174960000; + temp = 799; + } else if (n > 1600) { + i = 1399680000; + temp = 1599; + } + for (; i < Integer.MAX_VALUE; i++) { + if (isUgly(i)) { + temp++; + } + if (temp == n) { + return i; + } + } + return 0; + } + + /** + * 第N 个丑数 三指针算法 + * + * @param n + * @return + */ + public static int nthUglyNumber2(int n) { + + + + + + + return 0; + } } diff --git a/src/main/java/com/fancv/leetCode/mathematics/ReverseBits.java b/src/main/java/com/fancv/leetCode/mathematics/ReverseBits.java new file mode 100644 index 0000000..0bcf23b --- /dev/null +++ b/src/main/java/com/fancv/leetCode/mathematics/ReverseBits.java @@ -0,0 +1,25 @@ +package com.fancv.leetCode.mathematics; + +/** + * @author hamish-wu + */ +public class ReverseBits { + public static void main(String[] args) { + + int a = 0b11111111111111111111111111111101; + System.out.println(Integer.toBinaryString(reverseBits(a))); + } + + public static int reverseBits(int n) { + String s = Integer.toUnsignedString(n, 2); + int len = s.length(); + StringBuilder stringBuilder = new StringBuilder(); + while (len < 32) { + stringBuilder.append("0"); + len++; + } + stringBuilder.append(s).reverse(); + int s1 = Integer.parseUnsignedInt(stringBuilder.toString(),2); + return s1; + } +} diff --git a/src/main/java/com/fancv/leetCode/matrix/TransposedMartix.java b/src/main/java/com/fancv/leetCode/matrix/TransposedMartix.java new file mode 100644 index 0000000..8464bf6 --- /dev/null +++ b/src/main/java/com/fancv/leetCode/matrix/TransposedMartix.java @@ -0,0 +1,28 @@ +package com.fancv.leetCode.matrix; + +public class TransposedMartix { + + public static void main(String[] args) { + int a[][] = {{1, 2, 3, 11}, {4, 5, 6, 12}, {7, 8, 9, 13}}; + transpose(a); + + } + + public static int[][] transpose(int[][] matrix) { + int width = matrix.length; + int temp = -1; + for (int[] s : matrix) { + temp = s.length > temp ? s.length : temp; + } + int b[][] = new int[temp][width]; + + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[i].length; j++) { + + b[j][i] = matrix[i][j]; + } + + } + return b; + } +} diff --git a/src/main/java/com/fancv/stringLight/beautySum.java b/src/main/java/com/fancv/stringLight/beautySum.java new file mode 100644 index 0000000..0c9b5ae --- /dev/null +++ b/src/main/java/com/fancv/stringLight/beautySum.java @@ -0,0 +1,57 @@ +package com.fancv.stringLight; + +public class beautySum { + + public static void main(String[] args) { + String s = "aabcbaa"; + System.out.println(beautySum(s)); + } + + /** + * 1.计算出字符的所有可能子串 + * 2.计算子串的美丽数 + * 3.所有的美丽数求和 + * + * @param s + * @return + */ + public static int beautySum(String s) { + int sum = 0; + int len = s.length(); + + for (int i = 0; i < len - 2; i++) { + for (int j = i+3; j <= len; j++) { + String temp = s.substring(i, j); + sum = sum +beauty(temp); + } + } + return sum; + } + + /** + * 计算美丽数 + * + * 使用 int[26] 表示字符串出现次数 + * + * @param s + * @return + */ + public static int beauty(String s) { + System.out.println(s); + int[] counts = new int[26]; + char[] marcher = s.toCharArray(); + for (char a : marcher) { + counts[a - 'a']++; + } + int max = Integer.MIN_VALUE; + int min = Integer.MAX_VALUE; + for (int count : counts) { + if (count > 0) { + max = Math.max(max, count); + min = Math.min(min, count); + } + } + return max-min; + + } +} diff --git a/src/main/java/com/fancv/tree/MyTree.java b/src/main/java/com/fancv/tree/MyTree.java new file mode 100644 index 0000000..e2ee231 --- /dev/null +++ b/src/main/java/com/fancv/tree/MyTree.java @@ -0,0 +1,115 @@ +package com.fancv.tree; + +import java.util.LinkedList; + +/** + * 基本的树 + */ +public class MyTree { + + + /** + * 最普通的树的构造器 + * + * 分析若list 中没有null + * 则会退化成一个链表,总是填充左侧节点 + * 所以需要平衡二叉树 + * + * + * @param list + * @return + */ + public static TreeNode createBinaryTree(LinkedList list) { + TreeNode node = null; + if (list == null || list.isEmpty()) { + return null; + } + Integer data = list.removeFirst(); + if (data != null) { + node = new TreeNode(data); + node.leftChild = createBinaryTree(list); + node.rightChild = createBinaryTree(list); + } + return node; + } + + /** + * 前序遍历 + * @param node + */ + public static void preOrderTraveral(TreeNode node) { + if (node == null) { + return; + } + System.out.print(node.data + " "); + preOrderTraveral(node.leftChild); + preOrderTraveral(node.rightChild); + } + + /** + * 中序遍历 + * @param node + */ + public static void inOrderTraveral(TreeNode node) { + if (node == null) { + return; + } + inOrderTraveral(node.leftChild); + System.out.print(node.data + " "); + inOrderTraveral(node.rightChild); + } + + /** + * 后续遍历 + * @param node + */ + public static void postOrderTraveral(TreeNode node) { + if (node == null) { + return; + } + postOrderTraveral(node.leftChild); + postOrderTraveral(node.rightChild); + System.out.print(node.data + " "); + } + + public static void main(String[] args) { + LinkedList list = new LinkedList<>(); + list.add(1); + list.add(2); + list.add(3); + list.add(4); + list.add(5); + list.add(6); + list.add(7); + list.add(8); + list.add(9); + list.add(10); + list.add(11); + list.add(12); + + + TreeNode treeNode = createBinaryTree(list); + + + System.out.println("前序遍历:"); + preOrderTraveral(treeNode); + System.out.println("\n"+"中序遍历:"); + inOrderTraveral(treeNode); + System.out.println("\n"+"后序遍历:"); + postOrderTraveral(treeNode); + + } + + +} + + +class TreeNode { + public int data; + public TreeNode leftChild; + public TreeNode rightChild; + + public TreeNode(int data) { + this.data = data; + } +} \ No newline at end of file