From 63ca326724b01cab0994bf25a69939d0334ac66c Mon Sep 17 00:00:00 2001 From: kyriewhluo Date: Thu, 12 Sep 2024 19:55:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=B7=BB=E5=8A=A0=E5=85=B3?= =?UTF-8?q?=E4=BA=8E=E5=AD=97=E7=AC=A6=E4=B8=B2=E3=80=81=E5=AD=97=E8=8A=82?= =?UTF-8?q?=E5=92=8Cvoid=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在NumPy文档中,常规介绍部分现在包含了关于字符串、字节和void数据类型的信息,以及现有的数值类型。 --- pom.xml | 2 +- .../interview/random/StackForQueue.java | 111 ++++++++++++++++++ .../whaifree/leetCode/LinkedList/LCR155.java | 16 +++ .../tech/dataStructure/listSeries.java | 17 ++- .../tech/thread/AffinityThreadPoolTest.java | 2 +- 5 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 src/main/java/cn/whaifree/interview/random/StackForQueue.java create mode 100644 src/main/java/cn/whaifree/leetCode/LinkedList/LCR155.java diff --git a/pom.xml b/pom.xml index 3ce9832..6798be4 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ org.projectlombok lombok - 1.18.20 + 1.18.30 provided diff --git a/src/main/java/cn/whaifree/interview/random/StackForQueue.java b/src/main/java/cn/whaifree/interview/random/StackForQueue.java new file mode 100644 index 0000000..87a26d4 --- /dev/null +++ b/src/main/java/cn/whaifree/interview/random/StackForQueue.java @@ -0,0 +1,111 @@ +package cn.whaifree.interview.random; + +import java.util.ArrayDeque; +import java.util.Queue; + +public class StackForQueue { + + public static void main(String[] args) { + MyStack myStack = new MyStack(); + myStack.push(1); + myStack.push(2); + myStack.push(3); + System.out.println(myStack.peek()); + System.out.println(myStack.pop()); + System.out.println(myStack.size()); + while (myStack.size()!=0){ + System.out.println(myStack.pop()); + } + } + + static class MyStack{ + Queue queue1 = new ArrayDeque<>(); + Queue queue2 = new ArrayDeque<>(); + + void push(int x){ + queue1.add(x); + } + + int peek() { + if (queue1.isEmpty()) { + return Integer.MAX_VALUE; + } + while (queue1.size()>1){ + queue2.add(queue1.poll()); + } + Integer poll = queue1.poll(); + queue2.add(poll); + while (!queue2.isEmpty()) { + queue1.add(queue2.poll()); + } + return poll; + } + + int pop(){ + if (queue1.isEmpty()) { + return Integer.MAX_VALUE; + } + while (queue1.size()>1){ + queue2.add(queue1.poll()); + } + Integer poll = queue1.poll(); + while (!queue2.isEmpty()) { + queue1.add(queue2.poll()); + } + return poll; + } + + int size(){ + return queue1.size(); + } + + } +} + + +class MyStack { + Queue queue1 = null; + Queue queue2 = null; + public MyStack() { + queue1 = new ArrayDeque<>(); + queue2 = new ArrayDeque<>(); + } + + public void push(int x) { + queue1.add(x); + + } + + public int pop() { + if (queue1.isEmpty()) { + return Integer.MAX_VALUE; + } + while (queue1.size()>1){ + queue2.add(queue1.poll()); + } + Integer poll = queue1.poll(); + while (!queue2.isEmpty()) { + queue1.add(queue2.poll()); + } + return poll; + } + + public int top() { + if (queue1.isEmpty()) { + return Integer.MAX_VALUE; + } + while (queue1.size()>1){ + queue2.add(queue1.poll()); + } + Integer poll = queue1.poll(); + queue2.add(poll); + while (!queue2.isEmpty()) { + queue1.add(queue2.poll()); + } + return poll; + } + + public boolean empty() { + return queue1.isEmpty(); + } +} \ No newline at end of file diff --git a/src/main/java/cn/whaifree/leetCode/LinkedList/LCR155.java b/src/main/java/cn/whaifree/leetCode/LinkedList/LCR155.java new file mode 100644 index 0000000..5a60f1a --- /dev/null +++ b/src/main/java/cn/whaifree/leetCode/LinkedList/LCR155.java @@ -0,0 +1,16 @@ +package cn.whaifree.leetCode.LinkedList; + +import cn.whaifree.leetCode.model.TreeNode; + +public class LCR155 { + +// https://leetcode.cn/problems/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/description/ + + class Solution { + + + public TreeNode treeToDoublyList(TreeNode root) { + + } + } +} diff --git a/src/main/java/cn/whaifree/tech/dataStructure/listSeries.java b/src/main/java/cn/whaifree/tech/dataStructure/listSeries.java index 40a9c61..6ab8017 100644 --- a/src/main/java/cn/whaifree/tech/dataStructure/listSeries.java +++ b/src/main/java/cn/whaifree/tech/dataStructure/listSeries.java @@ -9,13 +9,26 @@ import java.util.concurrent.locks.ReentrantLock; public class listSeries { + public static void main(String[] args) throws InterruptedException { + while (true) { + Thread.sleep(1000); + } + } + + @Test + public void testFor() throws InterruptedException { + while (true) { + Thread.sleep(1000); + } + } + @Test public void test() throws IOException, ClassNotFoundException { ReentrantLock reentrantLock = new ReentrantLock(); } - public static void main(String[] args) throws IOException, ClassNotFoundException { + public static void ma1in(String[] args) throws IOException, ClassNotFoundException { List o = new ArrayList<>(); o.add(new User(1, "110")); @@ -50,6 +63,8 @@ public class listSeries { ", name='" + name + '\'' + '}'; } + + } } diff --git a/src/main/java/cn/whaifree/tech/thread/AffinityThreadPoolTest.java b/src/main/java/cn/whaifree/tech/thread/AffinityThreadPoolTest.java index bab97c7..748b8b5 100644 --- a/src/main/java/cn/whaifree/tech/thread/AffinityThreadPoolTest.java +++ b/src/main/java/cn/whaifree/tech/thread/AffinityThreadPoolTest.java @@ -45,7 +45,7 @@ public class AffinityThreadPoolTest { l = System.currentTimeMillis(); synchronized (o) { for (int i = 0; i < 3; i++) { - int finalI = i; + int finalI = i; // 在其他线程拿到 i 时,i 可能已经变了 executor.submit("A", () -> { System.out.println(Thread.currentThread().getName() + " A " + finalI); return null;