|
@@ -0,0 +1,137 @@
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Projectname: LeetCode
|
|
|
+ * @Filename: Exersice
|
|
|
+ * @Author: 杨逸
|
|
|
+ * @Data:2023/8/1 15:01
|
|
|
+ * @Description:
|
|
|
+ */
|
|
|
+public class Exercise {
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Solution solution = new Solution();
|
|
|
+ Codec codec = new Codec();
|
|
|
+ int t1[] = {10,5,2,6};
|
|
|
+ int t22[] = {2,3,1,2,4,3};
|
|
|
+
|
|
|
+
|
|
|
+ int t11[][] = {{3,2,0},{0,1,0},{0,3,0}};
|
|
|
+ int t12[][] = {{4,5},{7,10},{11,12},{14,15},{16,20}};
|
|
|
+ List<List<Integer>> list = new ArrayList<>();
|
|
|
+ ArrayList<Integer> list1 = new ArrayList<>();
|
|
|
+ list1.add(1);
|
|
|
+ list1.add(3);
|
|
|
+ ArrayList<Integer> list2 = new ArrayList<>();
|
|
|
+ list2.add(3);
|
|
|
+ list2.add(0);
|
|
|
+ list2.add(1);
|
|
|
+ ArrayList<Integer> list3 = new ArrayList<>();
|
|
|
+ list3.add(2);
|
|
|
+ ArrayList<Integer> list4 = new ArrayList<>();
|
|
|
+ list4.add(0);
|
|
|
+ list.add(list1);
|
|
|
+ list.add(list2);
|
|
|
+ list.add(list3);
|
|
|
+ list.add(list4);
|
|
|
+ char t2[][] = {
|
|
|
+ {'.','.','.','.','5','.','.','1','.'},
|
|
|
+ {'.','.','.','.','.','3','.','.','1'},
|
|
|
+ {'.','.','2','.','7','.','.','.','.'},
|
|
|
+ {'.','.','.','.','.','2','.','.','.'},
|
|
|
+ {'.','.','4','.','.','.','.','.','.'},
|
|
|
+ {'.','4','.','3','.','.','.','.','.'},
|
|
|
+ {'8','.','.','.','.','.','.','2','.'},
|
|
|
+ {'.','1','5','.','.','.','.','.','.'},
|
|
|
+ {'.','2','.','9','.','.','.','.','.'}};
|
|
|
+
|
|
|
+ String str1 = "114,117,207,117,235,82,90,67,143,146,53,108,200,91,80,223,58,170,110,236,81,90,222,160,165,195,187,199,114,235,197,187,69,129,64,214,228,78,188,67,205,94,205,169,241,202,144,240";
|
|
|
+
|
|
|
+ String str2 = "ad";
|
|
|
+ ListNode listNode1 = new ListNode(8);
|
|
|
+ ListNode listNode2 = new ListNode(9);
|
|
|
+ ListNode listNode3 = new ListNode(9);
|
|
|
+ ListNode listNode4 = new ListNode(3);
|
|
|
+ ListNode listNode5 = new ListNode(4);
|
|
|
+ ListNode listNode6 = new ListNode(5);
|
|
|
+ listNode1.next = listNode2;
|
|
|
+ listNode2.next = listNode3;
|
|
|
+
|
|
|
+ listNode4.next = listNode5;
|
|
|
+ listNode5.next = listNode6;
|
|
|
+
|
|
|
+ ListNode listNode7 = new ListNode(2);
|
|
|
+ ListNode listNode8 = new ListNode(10001);
|
|
|
+ ListNode listNode9 = new ListNode(10002);
|
|
|
+
|
|
|
+ listNode8.next = listNode9;
|
|
|
+
|
|
|
+ TreeNode root = new TreeNode(1);
|
|
|
+ TreeNode root1 = new TreeNode(2);
|
|
|
+ TreeNode root2 = new TreeNode(3);
|
|
|
+ TreeNode root3 = new TreeNode(4);
|
|
|
+ TreeNode root4 = new TreeNode(5);
|
|
|
+ TreeNode root5 = new TreeNode(6);
|
|
|
+ TreeNode root6 = new TreeNode(7);
|
|
|
+ TreeNode root7 = new TreeNode(3);
|
|
|
+ root.left = root1;
|
|
|
+ root.right = root2;
|
|
|
+ root2.left = root3;
|
|
|
+ root2.right = root4;
|
|
|
+
|
|
|
+ String serialize = codec.serialize(root);
|
|
|
+ System.out.println(serialize);
|
|
|
+ TreeNode node = codec.deserialize(serialize);
|
|
|
+ System.out.println("1");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //杨辉三角,DP
|
|
|
+ static void f(int n){
|
|
|
+ //DP
|
|
|
+ //使用二维数组保存数据
|
|
|
+ int mid = n-1;
|
|
|
+ int[][] dp = new int[n][2*n];
|
|
|
+ dp[0][mid] = 1;
|
|
|
+ for (int i = 1; i < n; i++) {
|
|
|
+ int cur_index = mid - i;
|
|
|
+ int size = i+1;
|
|
|
+ while(size != 0){
|
|
|
+ int v = 0;
|
|
|
+ //左上角
|
|
|
+ if (cur_index-1>=0){
|
|
|
+ v+=dp[i-1][cur_index-1];
|
|
|
+ }
|
|
|
+ //右上角
|
|
|
+ if (cur_index+1 < 2*n){
|
|
|
+ v += dp[i-1][cur_index+1];
|
|
|
+ }
|
|
|
+ dp[i][cur_index] = v;
|
|
|
+ cur_index +=2;
|
|
|
+ size--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int[] ints : dp) {
|
|
|
+ for (int anInt : ints) {
|
|
|
+ if (anInt == 0){
|
|
|
+ System.out.print("\t");
|
|
|
+ }else{
|
|
|
+ System.out.print(anInt + " ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //杨辉三角,递归
|
|
|
+ static int f2(int n,int m){
|
|
|
+ if (n == 1 && m == 1){
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ if (m < 1 || m > n){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return f2(n-1,m-1)+ f2(n-1,m);
|
|
|
+ }
|
|
|
+}
|