diff --git a/pom.xml b/pom.xml index 7f32bf0..3ce9832 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,22 @@ + + + org.projectlombok + lombok + 1.18.20 + provided + + + + + + + javax.persistence + javax.persistence-api + 2.2 + com.github.phantomthief simple-pool diff --git a/src/main/java/cn/whaifree/interview/DIDI/p1.java b/src/main/java/cn/whaifree/interview/DIDI/p1.java new file mode 100644 index 0000000..c93603b --- /dev/null +++ b/src/main/java/cn/whaifree/interview/DIDI/p1.java @@ -0,0 +1,169 @@ +package cn.whaifree.interview.DIDI; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.Scanner; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/7 17:24 + * @注释 + */ + +class p4{ + + + static long[] gezi = null; + static long max = 0; + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int num = scanner.nextInt(); + for (int i = 0; i < num; i++) { + int a = scanner.nextInt(); + long b = scanner.nextLong(); + gezi = new long[a]; + method(b, gezi, 0); + System.out.println(max); + max = Integer.MIN_VALUE; + } + } + + /** + * @param gezi 格子 + * @param num 物品数 + * @return + */ + public static void method(long num, long[] gezi,int start) { + if (num == 0) { + max = Math.max(cal(gezi), max); + return; + } + + for (int i = start; i < gezi.length; i++) { + gezi[i] += 1; + method(num - 1, gezi, i); + gezi[i] -= 1; + } + } + + public static long cal(long[] gezi) { + long res = 0; + for (int i = 0; i < gezi.length - 1; i++) { + res += Math.abs(gezi[i] - gezi[i + 1]); + } + return res; + } + +} +public class p1 { + + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int num = scanner.nextInt(); + for (int i = 0; i < num; i++) { + int a = scanner.nextInt(); + int b = scanner.nextInt(); + } + } + + /** + * dp[i][j] 前i个格子放入j个收藏品的最大美观度 + * + * dp[i][j] = max(dp[i-1][j-k]+(i-1)*k -k*(j-1)) + * 0 1 2 3 + * 0 0 0 0 0 + * 1 0 0 1 1 + * 2 0 0 + * + * + * 0 1 0 + * 0 3 0 + * 0 1 2 + * + * + * @param size 格子数量 + * @param num 物品数量 + */ + public static void method(int size, int num) { + int[][] dp = new int[size + 1][num + 1]; + for (int i = 0; i < dp.length; i++) { + Arrays.fill(dp[i], Integer.MIN_VALUE); + } + dp[0][0] = 0; + + + for (int i = 1; i <= size; i++) { + for (int j = 0; j <= num; j++) { + for (int k = 0; k <= j; k++) { + //可选择的物品 + dp[i][j] = Math.max(dp[i][j], dp[i][j - k] + (i - 1) * k - k * (j - 1)); + } + } + } + + int max = Integer.MIN_VALUE; + for (int i = 0; i < num; i++) { + max = Math.max(max, dp[size][i]); + } + System.out.println(max); + + } + + @Test + public void test() { + method(2, 2); + } + + +} + + +class p3{ + + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + int size = scanner.nextInt(); + int type = scanner.nextInt(); + int[][] costs = new int[type][type]; + for (int i = 0; i < type; i++) { + for (int j = 0; j < type; j++) { + costs[i][j] = scanner.nextInt(); + } + } + String next = scanner.next(); + path = new StringBuilder(next); + remove(costs); + System.out.println(maxCost); + } + + static StringBuilder path = null; + + static int tmpCost = 0; + static int maxCost = Integer.MIN_VALUE; + + public static void remove(int[][] map) { + if (path.isEmpty()) { + maxCost = Math.max(maxCost, tmpCost); + return; + } + + for (int i = 0; i < path.length() / 2; i++) { + StringBuilder tmpPath = new StringBuilder(path); + char a = path.charAt(i); + char b = path.charAt(i + 1); + int cost = map[a - 'a'][b - 'a']; + path.deleteCharAt(i); + path.deleteCharAt(i); + tmpCost += cost; + remove(map); + tmpCost -= cost; + path = tmpPath; + } + } + +} diff --git a/src/main/java/cn/whaifree/interview/HKWS/Write.java b/src/main/java/cn/whaifree/interview/HKWS/Write.java new file mode 100644 index 0000000..e410b53 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/HKWS/Write.java @@ -0,0 +1,69 @@ +//package cn.whaifree.interview.HKWS; +// +//import java.util.ArrayList; +//import java.util.HashMap; +//import java.util.HashSet; +//import java.util.Iterator; +// +///** +// * @version 1.0 +// * @Author whai文海 +// * @Date 2024/9/4 21:03 +// * @注释 +// */ +//public class Write { +// +// +// public static void main(String[] args) { +// +// ArrayList list1 = new ArrayList<>(); +// ArrayList list2 = new ArrayList<>(); +// +// for (int i = 0; i < 100000; i++) { +// list2.add(i); +// } +// +// HashSet set = new HashSet<>(); +// HashMap map = new HashMap<>(); +// +// for (int i = 30000; i < 50000; i++) { +// list1.add(i); +// set.add(i); +// map.put(i, new Object()); +// } +// +// Iterator iterator1 = list1.iterator(); +// Iterator iterator2 = list2.iterator(); +// +// +// long l = System.currentTimeMillis(); +// while (iterator2.hasNext()) { +// if (list1.contains(iterator2.next())) { // 相当于顺序便利int[] +// iterator2.remove(); +// } +// } +// System.out.println(System.currentTimeMillis() - l); // 2937 +// +// +// long l = System.currentTimeMillis(); +// list2.removeAll(list1); // 底层也是顺序便利 c.contains 挨个查 +// System.out.println(System.currentTimeMillis() - l); // 2862 +// +// +// long l = System.currentTimeMillis(); +// list2.removeAll(set); // c.contains 【map.contain】很快 +// System.out.println(System.currentTimeMillis() - l); // 8 +// +// +// long l = System.currentTimeMillis(); +// +// while (iterator2.hasNext()) { +// if (map.containsKey(iterator2.next())) { // map.containsKey +// iterator2.remove(); +// } +// } +// System.out.println(System.currentTimeMillis() - l); // 107 +// +// +// } +//} diff --git a/src/main/java/cn/whaifree/interview/Meituan/Metituan2.java b/src/main/java/cn/whaifree/interview/Meituan/Metituan2.java new file mode 100644 index 0000000..66686d5 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/Meituan/Metituan2.java @@ -0,0 +1,218 @@ +package cn.whaifree.interview.Meituan; + +import java.util.*; +import java.util.function.BiConsumer; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/7 10:02 + * @注释 + */ +public class Metituan2 { + +} + +class mt202{ + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int i = in.nextInt(); + long[] nums = new long[i]; + for (int i1 = 0; i1 < nums.length; i1++) { + nums[i1] = in.nextInt(); + } + Arrays.sort(nums); + method(nums); + + } + + /** + * + * @param nums + */ + public static void method(long[] nums) { + long minP = 0; + for (int i = 0; i < nums.length; i++) { + if (nums[i] % 2 == 0) { + minP += nums[i] + 1; + } + } + long minM = 0; + for (int i = 0; i < nums.length; i++) { + if (nums[i] % 2 == 1) { + minM += nums[i] + 1; + } + } + System.out.println(Math.min(minM, minP)); + } + + +} + +class mt203 { + + static class TreeNode { + int now; + List sonList; + + public TreeNode(int now, List sonList) { + this.now = now; + this.sonList = sonList; + } + + public int getNow() { + return now; + } + + public void setNow(int now) { + this.now = now; + } + + public List getSonList() { + return sonList; + } + + public void setSonList(List sonList) { + this.sonList = sonList; + } + } + + static Map> map = new HashMap<>(); + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int c = in.nextInt(); + for (int i = 0; i < c; i++) { + int num = in.nextInt(); + for (int j = 0; j < num; j++) { + int start = in.nextInt(); + int end = in.nextInt(); + if (map.containsKey(start)) { + map.get(start).add(end); + }else { + ArrayList value = new ArrayList<>(); + value.add(end); + map.put(start, value); + } + } + } + + // key 边的数量, + Map nMap = new HashMap<>(); + // 统计每个list的size + map.forEach(new BiConsumer>() { + @Override + public void accept(Integer integer, List integers) { + + } + }); + + } +} + +class cc{ + /** + * 1 + * 6 + * 1 2 + * 1 3 + * 3 7 + * 2 4 + * 2 6 + * @param args + */ + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + + // key 起始点 v 数量 每个节点对应子节点数量 + Map map = new HashMap<>(); + int c = in.nextInt(); + for (int i = 0; i < c; i++) { + int num = in.nextInt(); + for (int j = 0; j < num - 1; j++) { + int start = in.nextInt(); + int end = in.nextInt(); + map.put(start, map.getOrDefault(start, 0) + 1); + } + int leafSize = num - map.size(); + // key 节点数量 value几个节点有k这么多的子节点 + Map newMap = new HashMap<>(); + for (Integer key : map.keySet()) { + Integer v = map.get(key); + newMap.put(v, newMap.getOrDefault(v, 0) + 1); + } + + int res = 0; + for (Integer k : newMap.keySet()) { + Integer hasSize = newMap.get(k); + if (hasSize > 1) { + res+= hasSize; + } + } + // 组合 + res = res * (res - 1) / 2; + leafSize = leafSize * (leafSize - 1) / 2; + System.out.println(res + leafSize); + } + + + + } +} +class dd{ + + static HashMap> graph = new HashMap<>(); + static HashMap childCount = new HashMap<>(); + static HashMap countMap = new HashMap<>(); + + public static void main(String[] args) { + + Scanner in = new Scanner(System.in); + + + int c = in.nextInt(); + for (int i = 0; i < c; i++) { + int num = in.nextInt(); + int[][] path = new int[num][2]; + for (int j = 0; j < num - 1; j++) { + int start = in.nextInt(); + int end = in.nextInt(); + path[j][0] = start; + path[j][1] = end; + } + + for (int[] edge : path) { + if (!graph.containsKey(edge[0])) { + graph.put(edge[0], new ArrayList<>()); + } + graph.get(edge[0]).add(edge[1]); + } + + dfs(1); + int pairCount = 0; + for (Integer value : countMap.values()) { + if (value > 1) { + pairCount += value * (value - 1) / 2; + } + } + System.out.println(pairCount); + } + } + + + public static void dfs(int node) { + + int count = 0; + if (graph.containsKey(node)) { + for (Integer child : graph.get(node)) { + count += graph.get(node).size(); + dfs(child); + } + } + count++; + childCount.put(node, count); + countMap.put(count, countMap.getOrDefault(count, 0) + 1); + + } +} + diff --git a/src/main/java/cn/whaifree/interview/XieChen/p1.java b/src/main/java/cn/whaifree/interview/XieChen/p1.java new file mode 100644 index 0000000..6879027 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/XieChen/p1.java @@ -0,0 +1,192 @@ +package cn.whaifree.interview.XieChen; + +import org.junit.Test; + +import java.util.*; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/5 19:09 + * @注释 + */ +public class p1 { + + @Test + public void test1() { + +// Map map =countOrdersPerUser(orders); + String maxUser = null; + Integer max = 0; + + } + + @Test + public void test() { + System.out.println(cal(new int[]{0}, 0, 0)); + } + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int i = in.nextInt(); + String next = in.next(); + String[] split = next.split(""); + int[] nums = new int[i]; + for (int i1 = 0; i1 < split.length; i1++) { + nums[i1] = Integer.parseInt(split[i1]); + } + int method = method(nums); + System.out.println(method); + + } + + public static int method(int[] nums) { + + // 权重为0的数量 + + + int count = 0; + int length = nums.length; + for (int start = 0; start < length; start++) { + for (int len = 0; start + len < length; len += 2) { + int weight = cal(nums, start, start + len); + if (weight % 2 == 1) { + count++; + } + } + } + + return count; + + } + + + public static int cal(int[] nums, int start, int end) { + int weight = 0; + int last = 1; + for (int i = start; i <= end; i++) { + if (nums[i] != last) { + weight++; + last = nums[i]; + } + } + + + return weight; + } + + +} + + +class p442{ + + public static void main(String[] args) { + System.out.println(method(7 ,4, 7653)); + + Scanner in = new Scanner(System.in); + int n = in.nextInt(); + int m = in.nextInt(); + int k = in.nextInt(); + + System.out.println(method(n, m, k)); + } + + + + + static int nowSum = 0; + static int res = 0; + static Set set = new HashSet<>(); + /** + * + * @param n 背包物品 + * @param m + * @param k + * @return + */ + public static int method(int n, int m, int k) { + circle(n, 0, m, k); + return res; + } + + + public static void circle(int n, int start, int m, int k) { + + if (m < 0) { + return; + } + + if (nowSum > k) { + res++; + System.out.println(nowSum); + } + + for (int i = 0; i <= n; i++) { + if (set.contains(i)) { + continue; + } + set.add(i); + int tmp = nowSum; + nowSum = nowSum * 10 + i; + circle(n, i + 1, m - 1, k); + nowSum = tmp; + set.remove(i); + } + + } + + +} + +class p3{ + + public static void main(String[] args) { + + } + +} + +class p4{ + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int n = in.nextInt(); + int k = in.nextInt(); + int sum = in.nextInt(); + int[] nums = new int[n]; + for (int i = 0; i < n; i++) { + nums[i] = in.nextInt(); + } + + + int res = 0; + for (int i = 0; i <= n - k; i++) { + int start = i; + int end = i + k - 1; + int tmpSum = 0; + for (int j = start; j <= end; j++) { + tmpSum += nums[j]; + } + + int needSub = tmpSum - sum; + int reduceIndex = end; + int count = 0; + while (needSub > 0) { + if (needSub > nums[reduceIndex]) { + count += nums[reduceIndex]; + needSub -= nums[reduceIndex]; + nums[reduceIndex] = 0; + reduceIndex--; + } else { + count += needSub; + nums[reduceIndex] -= needSub; + needSub = 0; + } + } + res += count; + } + System.out.println(Arrays.toString(nums)); + + System.out.println(res); + } +} diff --git a/src/main/java/cn/whaifree/interview/ccn/p1/c2.java b/src/main/java/cn/whaifree/interview/ccn/p1/c2.java new file mode 100644 index 0000000..f9053f8 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/ccn/p1/c2.java @@ -0,0 +1,10 @@ +package cn.whaifree.interview.ccn.p1; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/10 23:36 + * @注释 + */ +public class c2 { +} diff --git a/src/main/java/cn/whaifree/interview/ccn/p2.java b/src/main/java/cn/whaifree/interview/ccn/p2.java new file mode 100644 index 0000000..9857525 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/ccn/p2.java @@ -0,0 +1,111 @@ +package cn.whaifree.interview.ccn; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/8 0:04 + * @注释 + */ +public class p2 { + + @Test + public void test() { + ArrayList ls = new ArrayList<>(); + ls.add(50); + System.out.println(chooseBestSum(163,3, ls)); + } + + + static int now = 0; + static List path = new ArrayList<>(); + static int res = 0; + /** + * ls里找到k个数,总和不超过t的最大 + * @param t + * @param k + * @param ls + * @return + */ + int chooseBestSum(int t, int k, List ls) { + // 在这⾥写代码 + back(t, k, ls, 0); + return res; + } + + void back(int t, int k, List ls,int start) { + if (path.size() == k && now <= t) { + res = Math.max(res, now); + } + if (now > t || path.size() > k) { + return; + } + + for (int i = start; i < ls.size(); i++) { + Integer e = ls.get(i); + now += e; + path.add(e); + back(t, k, ls, i + 1); + path.remove(path.size() - 1); + now -= e; + } + } +} + +class c4{ + + + public static void main(String[] args) { + System.out.println(formatDuration(62)); + } + final static int MINUTE = 60; + final static int HOUR = 60 * MINUTE; + final static int DAYS = 24 * HOUR; + final static int YEAR = 365 * DAYS; + // 本题面试官已设置测试用例 + public static String formatDuration(int seconds) { + // 在这⾥写代码 + int year = 0; + int day = 0; + int hour = 0; + int minute =0; + if(seconds>YEAR){ + year = seconds/YEAR; + seconds%=YEAR; + } + if (seconds > HOUR) { + hour = seconds / HOUR; + seconds %= HOUR; + } + if (seconds > DAYS) { + day = seconds / DAYS; + seconds %= DAYS; + } + if(seconds>MINUTE){ + minute = seconds/MINUTE; + seconds%=MINUTE; + } + if (seconds != 0) { + + } + + + /** + * - 微服务限流方案 + * + * 架构图 + * 指标选择、计算、指标精确性 + * 限流策略 + * 具体实现 + * - 限流 + * - 拒绝服务实现 + */ + + return ""; + } + +} diff --git a/src/main/java/cn/whaifree/interview/haoweilai/p1.java b/src/main/java/cn/whaifree/interview/haoweilai/p1.java new file mode 100644 index 0000000..9e02571 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/haoweilai/p1.java @@ -0,0 +1,73 @@ +package cn.whaifree.interview.haoweilai; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.HashMap; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/7 22:24 + * @注释 + */ +public class p1 { + + @Test + public void test() { + System.out.println(tribonacci(25)); + } + + /** + * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 + * + * + * @param n int整型 + * @return int整型 + */ + public int tribonacci (int n) { + + int[] dp = new int[n + 1]; + dp[0] = 0; + dp[1] = 1; + dp[2] = 1; + for (int i = 3; i < dp.length; i++) { + dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]; + } + return dp[n]; + } +} + + +class c2{ + + + public static void main(String[] args) { + + c2 c2 = new c2(); + System.out.println(Arrays.toString(c2.twoSum(new int[]{1, -2, -3, -4}, -5))); + } + /** + * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 + * + * + * @param nums int整型一维数组 + * @param target int整型 + * @return int整型一维数组 + */ + public int[] twoSum (int[] nums, int target) { + // write code here + HashMap map = new HashMap<>(); + for (int i = 0; i < nums.length; i++) { + map.put(nums[i], i); + } + + for (int i = 0; i < nums.length; i++) { + int need = target - nums[i]; + if (map.containsKey(need)) { + return new int[]{i, map.get(need)}; + } + } + return null; + } +} diff --git a/src/main/java/cn/whaifree/interview/qnr/P1.java b/src/main/java/cn/whaifree/interview/qnr/P1.java new file mode 100644 index 0000000..a8fe887 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/qnr/P1.java @@ -0,0 +1,222 @@ +package cn.whaifree.interview.qnr; + +import org.junit.Test; + +import java.util.*; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/6 18:25 + * @注释 + */ +public class P1 { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int num = in.nextInt(); + int[] nums = new int[num]; + for (int i = 0; i < num; i++) { + nums[i] = in.nextInt(); + } + + + method(nums,nums.length); + in.close(); + for (Integer i : min) { + System.out.print(i); + System.out.print(" "); + } + } + + static List min = null; + + static List path = new ArrayList<>(); + + public static void method(int[] nums,int size) { + if (size <= 0) { + if (min == null) { + min = new ArrayList<>(path); + return; + } + if (isPre(min, path)) { + min = new ArrayList<>(path); + } + return; + } + + + for (int i = 0; i < nums.length; i++) { + if (path.contains(nums[i])) { + continue; + } + if (isPre(min, path)) { + continue; + } + path.add(nums[i]); + method(nums, size - 1); + path.remove(path.size() - 1); + } + } + + /** + * a 的字典序列>b + * + * @param a + * @param b + * @return + */ + public static boolean isPre(List a, List b) { + if (a == null || b == null) { + return false; + } + int minLen = Math.min(a.size(), b.size()); + for (int i = 0; i < minLen; i++) { + Integer c1 = a.get(i); + Integer c2 = b.get(i); + // -1 2 + if (c1 < 0 && c2 > 0) { + return false; + } else if (c1 > 0 && c2 < 0) { + return true; + } + + if (c1 > c2) { + return true; + } else if (c1 < c2) { + return false; + } + } + return false; + } + + @Test + public void test() { + List list = Arrays.asList(-1, 1, 2); + List list1 = Arrays.asList(-1, 2, 1); + System.out.println(isPre(list1, list)); + } + + + + +} + +class p2{ + + + + public static void main(String[] args) { + + Scanner in = new Scanner(System.in); + int num = in.nextInt(); + long sum = in.nextLong(); + long[] a = new long[num]; + for (int i = 0; i < num; i++) { + a[i] = in.nextInt(); + } + + long[] b = new long[num]; + for (int i = 0; i < num; i++) { + b[i] = in.nextInt(); + } + + method(a, b, sum); + } + + /** + * + * dp + * + * @param A + * @param B + * @param sum + */ + public static void method(long[] A, long[] B, long sum) { + + /** + * 二分查找 + * + */ + + int left = 0; + int right = A.length; + while (left < right) { + int mid = (left + right) / 2; + if (maxP(A, B, left, right)>sum) { + right = mid; + }else { + left = mid + 1; + } + } + + + int minLen = 0; + + for (int i = 0; i < A.length; i++) { + long x = maxP(A, B, 0, i); + if (x >= sum) { + minLen = Math.min(minLen, i + 1); + break; + } + } + System.out.println(minLen == Integer.MAX_VALUE ? -1 : minLen); + + } + + /** + * 检查 + * @param A + * @param B + * @param left + * @param right + * @return + */ + public static long maxP(long[] A, long[] B, int left, int right) { + long[] tmpA = Arrays.copyOfRange(A, left, right + 1); + long[] tmpB = Arrays.copyOfRange(B, left, right + 1); + Arrays.sort(tmpA); + Arrays.sort(tmpB); + long sum = 0; + for (int i = 0; i < tmpA.length; i++) { + sum += tmpA[i] * tmpB[i]; + } + return sum; + } + + + +} + +class p3{ + + public static void main(String[] args) { + System.out.println((int)'9'-'0'); + + } + + /** + * 有多少个子串,子串内部每个数字的数量都相等数量相等 + * @param string + */ + public static void method(String string) { + char[] charArray = string.toCharArray(); + /** + * 截止key每个位置 + * value,对应数字的数量 + */ + Map map = new HashMap<>(); + + for (int i = 0; i < charArray.length; i++) { + if (map.containsKey(i)) { + map.get(i)[charArray[i] - '0'] += 1; + }else { + int[] value = new int[10]; + value[charArray[i] - '0'] = 1; + map.put(i, value); + } + } + } + + +} diff --git a/src/main/java/cn/whaifree/redo/redo_all_240721/LeetCode131.java b/src/main/java/cn/whaifree/redo/redo_all_240721/LeetCode131.java index 0090241..dc20a1a 100644 --- a/src/main/java/cn/whaifree/redo/redo_all_240721/LeetCode131.java +++ b/src/main/java/cn/whaifree/redo/redo_all_240721/LeetCode131.java @@ -1,5 +1,7 @@ package cn.whaifree.redo.redo_all_240721; +import org.junit.Test; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -81,6 +83,7 @@ public class LeetCode131 { List> res = new ArrayList<>(); List path = new ArrayList<>(); + public List> partition(String s) { back(s, 0); return res; @@ -111,4 +114,56 @@ public class LeetCode131 { return true; } } + + + @Test + public void test() { + new Sol().partition("aabaacac"); + } + static class Sol { + + /** + * dp[i][j] 表示i-j是否是回文串 + * + * if s[i]==s[j] && dp[i+1][j-1| + * true + * i从大到小,j从小到大 + * + * + * @param s + * @return + */ + public List> partition(String s) { + char[] charArray = s.toCharArray(); + boolean[][] dp = new boolean[charArray.length + 1][charArray.length + 1]; +// for (int i = 0; i < dp.length; i++) { +// dp[i][i] = true; +// } + + for (int i = charArray.length; i > 0; i--) { + for (int j = i; j <= charArray.length; j++) { + if (charArray[i - 1] == charArray[j - 1] && (j - i < 2 || dp[i + 1][j - 1])) { + dp[i][j] = true; + } + } + } + + for (int i = 0; i < charArray.length; i++) { + for (int j = i; j < charArray.length; j++) { + if (dp[i][j]) { + System.out.println(s.substring(i - 1, j)); + } + } + } + return null; + } + + public static void main(String[] args) { + while (true) { + + } + } + } + + } diff --git a/src/main/java/cn/whaifree/test/OptimisticLock.java b/src/main/java/cn/whaifree/test/OptimisticLock.java new file mode 100644 index 0000000..cd4d04a --- /dev/null +++ b/src/main/java/cn/whaifree/test/OptimisticLock.java @@ -0,0 +1,27 @@ +package cn.whaifree.test; + +import lombok.Data; + +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Version; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/7 23:00 + * @注释 + */ + +public class OptimisticLock { + + @Data + static class User{ + + @Id + @GeneratedValue + int id; + @Version + private int version; + } +} diff --git a/src/main/java/cn/whaifree/test/cd.java b/src/main/java/cn/whaifree/test/cd.java new file mode 100644 index 0000000..3550ec5 --- /dev/null +++ b/src/main/java/cn/whaifree/test/cd.java @@ -0,0 +1,27 @@ +package cn.whaifree.test; + +import java.util.Arrays; + +/** + * @version 1.0 + * @Author whai文海 + * @Date 2024/9/7 12:44 + * @注释 + */ +public enum cd { + A(1, "@"), + ; + int age; + String name; + + cd(int age, String name) { + this.age = age; + this.name = name; + } + + public static void main(String[] args) { + System.out.println(Arrays.toString(cd.values())); + System.out.println(cd.valueOf("A")); + + } +}