摘要: 128 最长连续序列 public class Solution { public int longestConsecutive(int[] nums) { if (nums == null || nums.length == 0) return 0; int ans = 1; HashMap<In 阅读全文
posted @ 2023-12-22 16:52 Vivid-BinGo 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 简介 KMP算法是一种改进的字符串匹配算法,由D.E.Knuth、J.H.Morris和V.R.Pratt提出,因此人们称它为克努特—莫里斯—普拉特操作(简称KMP算法)。KMP算法的核心是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的。 实现 构造 next[] 数组 前 阅读全文
posted @ 2023-12-08 18:57 Vivid-BinGo 阅读(2) 评论(0) 推荐(0) 编辑
摘要: CD79 一种消息接收并打印的结构设计 public class CD79_1 { public static class Node { public int num; public Node next; public Node(int num) { this.num = num; } } publ 阅读全文
posted @ 2023-11-26 21:05 Vivid-BinGo 阅读(17) 评论(0) 推荐(0) 编辑
摘要: CD66 并查集的实现 public class CD66_1 { public static class Solution { int[] f; public Solution(int n) { f = new int[n]; Arrays.fill(f, -1); } private int f 阅读全文
posted @ 2023-11-26 12:37 Vivid-BinGo 阅读(15) 评论(0) 推荐(0) 编辑
摘要: CDxxx 从 5 随机到 7 随机及其扩展 /* rand1To5实现等概率随机产生1~7的随机函数rand1To7 */ public int rand1To5() { return (int) (Math.random() * 5) + 1; } public int rand1To7() { 阅读全文
posted @ 2023-11-24 18:16 Vivid-BinGo 阅读(2) 评论(0) 推荐(0) 编辑
摘要: CD26 子数组的最大累加和问题 public class CD26_1 { public static int solution(int[] arr) { int ans = -1, sum = 0; for (int num : arr) { if (sum + num > 0) { sum + 阅读全文
posted @ 2023-11-23 22:03 Vivid-BinGo 阅读(3) 评论(0) 推荐(0) 编辑
摘要: CD149 转圈打印矩阵 public class CD149_1 { public static void solution(int[][] arr) { int up = 0, down = arr.length - 1, left = 0, right = arr[0].length - 1; 阅读全文
posted @ 2023-11-22 18:41 Vivid-BinGo 阅读(4) 评论(0) 推荐(0) 编辑
摘要: CD142 不用额外变量交换两个整数的值 /* 模拟 */ public class CD142_1 { public static void solution(int a, int b) { a = a ^ b; b = a ^ b; a = a ^ b; System.out.println(a 阅读全文
posted @ 2023-11-21 16:28 Vivid-BinGo 阅读(1) 评论(0) 推荐(0) 编辑
摘要: CD126 括号字符串的有效性 /* 模拟 */ public class CD126_1 { public static String solution(String s) { int l = 0, r = 0; for (char ch : s.toCharArray()) { if (ch = 阅读全文
posted @ 2023-11-20 13:33 Vivid-BinGo 阅读(8) 评论(0) 推荐(0) 编辑
摘要: CD95 判断两个字符串是否互为变形词 /* 模拟 */ public class CD95_1 { public static boolean solution(String s1, String s2) { if (s1.length() != s2.length()) return false 阅读全文
posted @ 2023-11-16 14:04 Vivid-BinGo 阅读(10) 评论(0) 推荐(0) 编辑
摘要: CD42 子数组异或和为 0 的最多划分⭐ /*⭐DP⭐*/ public class CD42_1 { public static int solution(int[] arr) { HashMap<Integer, Integer> map = new HashMap<>(); int[] dp 阅读全文
posted @ 2023-11-14 21:09 Vivid-BinGo 阅读(4) 评论(0) 推荐(0) 编辑
摘要: CD183 斐波那契数列问题的递归和动态规划1 /* * 矩阵快速幂 * [f(n), f(n-1)] = [1, 1] x [[1, 1], [1, 0]]^(n-2) */ public class CD183_1 { public static long solution(long n) { 阅读全文
posted @ 2023-11-13 22:11 Vivid-BinGo 阅读(1) 评论(0) 推荐(0) 编辑
摘要: CD172 判断二叉树是否为平衡二叉树 /* 递归 */ public class CD172_1 { public static class TreeNode { public int val; public TreeNode left; public TreeNode right; public 阅读全文
posted @ 2023-11-12 21:42 Vivid-BinGo 阅读(2) 评论(0) 推荐(0) 编辑
摘要: CD161 用递归和非递归方式实现二叉树先序、中序和后序遍历❗ public class CD161_1 { public static class TreeNode { public int val; public TreeNode left; public TreeNode right; pub 阅读全文
posted @ 2023-11-10 20:13 Vivid-BinGo 阅读(3) 评论(0) 推荐(0) 编辑
摘要: CDxxx 两个单链表相交的一系列问题⭐ 剑指offer 链表篇 JZ52 两个链表的第一个公共结点 剑指offer 链表篇 JZ23 链表中环的入口结点 public Node getIntersectNode(Node head1, Node head2) { if (head1 == null 阅读全文
posted @ 2023-11-09 13:50 Vivid-BinGo 阅读(1) 评论(0) 推荐(0) 编辑