From 02f9c26f696774c9db2aa7bef4ac25f9d4b28803 Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Sat, 1 Apr 2023 12:42:01 +0800 Subject: [PATCH 1/7] =?UTF-8?q?updaye=200232.=E7=94=A8=E6=A0=88=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E9=98=9F=E5=88=97=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=A4=8D?= =?UTF-8?q?=E6=9D=82=E5=BA=A6=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0232.用栈实现队列.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/problems/0232.用栈实现队列.md b/problems/0232.用栈实现队列.md index efeb1046..4a57ee96 100644 --- a/problems/0232.用栈实现队列.md +++ b/problems/0232.用栈实现队列.md @@ -112,6 +112,10 @@ public: ``` +* 时间复杂度: push和empty为O(1), pop和peek为O(n) +* 空间复杂度: O(n) + + ## 拓展 可以看出peek()的实现,直接复用了pop(), 要不然,对stOut判空的逻辑又要重写一遍。 From 1b6e26be2bf4f2dd584b3b59e4781a9d79cd4b48 Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Sat, 1 Apr 2023 12:45:02 +0800 Subject: [PATCH 2/7] =?UTF-8?q?update=200225.=E7=94=A8=E9=98=9F=E5=88=97?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=A0=88=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=A4=8D?= =?UTF-8?q?=E6=9D=82=E5=BA=A6=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0225.用队列实现栈.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/problems/0225.用队列实现栈.md b/problems/0225.用队列实现栈.md index 16b9e47c..bad2faec 100644 --- a/problems/0225.用队列实现栈.md +++ b/problems/0225.用队列实现栈.md @@ -111,6 +111,8 @@ public: } }; ``` +* 时间复杂度: push为O(n),其他为O(1) +* 空间复杂度: O(n) # 优化 @@ -156,6 +158,9 @@ public: } }; ``` +* 时间复杂度: push为O(n),其他为O(1) +* 空间复杂度: O(n) + # 其他语言版本 From 916718824bd6fe521ee2164b29f71d11633828a7 Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Sat, 1 Apr 2023 12:47:36 +0800 Subject: [PATCH 3/7] =?UTF-8?q?update=200020.=E6=9C=89=E6=95=88=E7=9A=84?= =?UTF-8?q?=E6=8B=AC=E5=8F=B7=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E5=BA=A6=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0020.有效的括号.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/problems/0020.有效的括号.md b/problems/0020.有效的括号.md index a25129c5..213d61b7 100644 --- a/problems/0020.有效的括号.md +++ b/problems/0020.有效的括号.md @@ -135,6 +135,9 @@ public: }; ``` +* 时间复杂度: O(n) +* 空间复杂度: O(n) + 技巧性的东西没有固定的学习方法,还是要多看多练,自己灵活运用了。 From 2633b1a346e106e8d14ee6404f1cf50cfb83a0af Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Sat, 1 Apr 2023 12:50:29 +0800 Subject: [PATCH 4/7] =?UTF-8?q?update=201047.=E5=88=A0=E9=99=A4=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E4=B8=AD=E7=9A=84=E6=89=80=E6=9C=89=E7=9B=B8?= =?UTF-8?q?=E9=82=BB=E9=87=8D=E5=A4=8D=E9=A1=B9:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=8D=E6=9D=82=E5=BA=A6=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1047.删除字符串中的所有相邻重复项.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/problems/1047.删除字符串中的所有相邻重复项.md b/problems/1047.删除字符串中的所有相邻重复项.md index 810f7292..694f1a92 100644 --- a/problems/1047.删除字符串中的所有相邻重复项.md +++ b/problems/1047.删除字符串中的所有相邻重复项.md @@ -77,6 +77,9 @@ public: } }; ``` +* 时间复杂度: O(n) +* 空间复杂度: O(n) + 当然可以拿字符串直接作为栈,这样省去了栈还要转为字符串的操作。 @@ -99,6 +102,8 @@ public: } }; ``` +* 时间复杂度: O(n) +* 空间复杂度: O(1),返回值不计空间复杂度 ## 题外话 From 6cd25d1fc5f98a02c7ef1ad52ad416c39d7357a4 Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Sat, 1 Apr 2023 12:53:40 +0800 Subject: [PATCH 5/7] =?UTF-8?q?update=200150.=E9=80=86=E6=B3=A2=E5=85=B0?= =?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=B1=82=E5=80=BC:=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=8D=E6=9D=82=E5=BA=A6=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0150.逆波兰表达式求值.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/problems/0150.逆波兰表达式求值.md b/problems/0150.逆波兰表达式求值.md index f0323bc4..09cc4f96 100644 --- a/problems/0150.逆波兰表达式求值.md +++ b/problems/0150.逆波兰表达式求值.md @@ -113,6 +113,9 @@ public: }; ``` +* 时间复杂度: O(n) +* 空间复杂度: O(n) + ## 题外话 From 1662ac347d28f35073066dba2761cd9d0c4bcf35 Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Sat, 1 Apr 2023 12:55:37 +0800 Subject: [PATCH 6/7] =?UTF-8?q?update=200239.=E6=BB=91=E5=8A=A8=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E6=9C=80=E5=A4=A7=E5=80=BC=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=8D=E6=9D=82=E5=BA=A6=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0239.滑动窗口最大值.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/problems/0239.滑动窗口最大值.md b/problems/0239.滑动窗口最大值.md index 540ab5d7..f1c4b76c 100644 --- a/problems/0239.滑动窗口最大值.md +++ b/problems/0239.滑动窗口最大值.md @@ -184,6 +184,9 @@ public: } }; ``` +* 时间复杂度: O(n) +* 空间复杂度: O(k) + 再来看一下时间复杂度,使用单调队列的时间复杂度是 O(n)。 From b28ba70ee1464fbd915c5d655bd6865a7d2d66e0 Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Sat, 1 Apr 2023 12:57:24 +0800 Subject: [PATCH 7/7] =?UTF-8?q?update=20=200347.=E5=89=8DK=E4=B8=AA?= =?UTF-8?q?=E9=AB=98=E9=A2=91=E5=85=83=E7=B4=A0=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=8D=E6=9D=82=E5=BA=A6=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0347.前K个高频元素.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/problems/0347.前K个高频元素.md b/problems/0347.前K个高频元素.md index d8eabef4..0d268d9b 100644 --- a/problems/0347.前K个高频元素.md +++ b/problems/0347.前K个高频元素.md @@ -79,8 +79,6 @@ ```CPP -// 时间复杂度:O(nlogk) -// 空间复杂度:O(n) class Solution { public: // 小顶堆 @@ -120,6 +118,10 @@ public: } }; ``` + +* 时间复杂度: O(nlogk) +* 空间复杂度: O(n) + # 拓展 大家对这个比较运算在建堆时是如何应用的,为什么左大于右就会建立小顶堆,反而建立大顶堆比较困惑。