refactor(interview): 重命名ccn包为zhaoyun包

将'cn.whaifree.interview.ccn'包重命名为'cn.whaifree.interview.zhaoyun',以反映新的命名约定。c2.java和p2.java文件中的包声明已更新。

feat(redo): 添加LeetCode718和LeetCode1143题目解决方案

新增'LeetCode718'和'LeetCode1143'两个类,分别提供'最长公共子数组'和'最长公共子序列'问题的解决方案。包括单元测试和算法实现。
This commit is contained in:
whaifree 2024-09-15 23:59:52 +08:00
parent 63ca326724
commit ad890c9d8a
2 changed files with 240 additions and 3 deletions

View File

@ -0,0 +1,109 @@
package cn.whaifree.designPattern.ChainPattern;
import lombok.Setter;
import java.util.Scanner;
/**
*
* <a href="https://kamacoder.com/problempage.php?pid=1100">...</a>
*
* @version 1.0
* @Author whai文海
* @Date 2024/9/12 23:37
* @注释
*/
public class ChainPattern {
}
class Main{
public static void main(String[] args) {
Audit.Builder builder = new Audit.Builder();
AbstractAudit build = builder.setAudit(new Supervisor())
.setAudit(new Manager())
.setAudit(new Director())
.build();
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
for (int j = 0; j < i; j++) {
build.process(scanner.next(), scanner.nextInt());
}
}
}
interface Audit{
void process(String name,int day);
public static class Builder{
AbstractAudit head;
public Builder setAudit(AbstractAudit audit) {
if (head == null) {
head = audit;
}else {
AbstractAudit index = head;
index.setNext(audit);
}
return this;
}
public AbstractAudit build(){
return head;
}
}
}
@Setter
abstract class AbstractAudit implements Audit{
Audit next;
}
class Supervisor extends AbstractAudit {
@Override
public void process(String name,int day) {
if (day <= 3) {
System.out.println(name + " Approved by Supervisor");
}
else {
this.next.process(name, day);
}
}
}
class Manager extends AbstractAudit {
@Override
public void process(String name,int day) {
if (day > 3 && day <= 7) {
System.out.println(name + " Approved by Manager");
}else {
this.next.process(name, day);
}
}
}
class Director extends AbstractAudit {
@Override
public void process(String name,int day) {
if (day<=10&&day > 7) {
System.out.println(name + " Approved by Director");
}else {
System.out.println(name + " Denied by Director.");
}
}
}

View File

@ -1,16 +1,144 @@
package cn.whaifree.leetCode.LinkedList;
import cn.whaifree.leetCode.model.TreeNode;
import org.junit.Test;
import java.util.*;
public class LCR155 {
// https://leetcode.cn/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/description/
public static void main(String[] args) {
new Thread(() -> {
List<byte[]> list = new ArrayList<byte[]>();
while (true) {
//
}
}).start();
// 线程二
new Thread(() -> {
while (true) {
System.out.println(new Date().toString() + Thread.currentThread() + "==");
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
// https://leetcode.cn/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/description/
static class Node {
public int val;
public Node left;
public Node right;
public Node() {
}
public Node(int _val) {
val = _val;
}
public Node(int _val, Node _left, Node _right) {
val = _val;
left = _left;
right = _right;
}
}
@Test
public void test() {
Node node1 = new Node(4);
node1.left = new Node(2);
node1.right = new Node(5);
node1.left.left = new Node(1);
node1.left.right = new Node(3);
Node node = new Solution1().treeToDoublyList(node1);
}
class Solution {
public Node treeToDoublyList(Node root) {
public TreeNode treeToDoublyList(TreeNode root) {
if (root == null) {
return null;
}
if (root.left == null && root.right == null) {
root.right = root;
root.left = root;
return root;
}
List<Node> nodes = new ArrayList<>();
Deque<Node> deque = new LinkedList<>();
deque.add(root);
while (!deque.isEmpty()) {
Node pop = deque.pop();
if (pop != null) {
if (pop.right != null) {
deque.push(pop.right);
}
deque.push(pop);
deque.push(null);
if (pop.left != null) {
deque.push(pop.left);
}
}else {
nodes.add(deque.pop());
}
}
Node head = new Node(Integer.MAX_VALUE);
Node index = head;
for (int i = 0; i < nodes.size() - 1; i++) {
Node node = nodes.get(i);
index.right = node;
node.left = index;
index = index.right;
}
Node node = nodes.get(nodes.size() - 1);
index.right = node;
node.left = index;
node.right = head.right;
head.right.left = node;
return head.right;
}
}
class Solution1 {
Node pre;
Node index;
public Node treeToDoublyList(Node root) {
pre = new Node(-1);
index = pre;
in(root);
index.right = pre.right;
pre.right.left = index;
return pre.right;
}
public void in(Node root) {
if (root == null) {
return;
}
in(root.left);
index.right = root;
root.left = index;
index = index.right;
in(root.right);
}
}
}