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;