From 86151a6d8b42c2686cbdf4e443e6cc42c4ecc7ca Mon Sep 17 00:00:00 2001 From: LetMeFly666 <814114971@qq.com> Date: Tue, 26 Nov 2024 23:51:02 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=B7=BB=E5=8A=A0=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E2=80=9C3206.=E4=BA=A4=E6=9B=BF=E7=BB=84I=E2=80=9D=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=92=8C=E9=A2=98=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0743-network-delay-time_20241125-half.cpp | 27 ++++ Codes/3206-alternating-groups-i.cpp | 22 +++ Codes/3206-alternating-groups-i.go | 16 +++ Codes/3206-alternating-groups-i.java | 17 +++ Codes/3206-alternating-groups-i.py | 11 ++ README.md | 1 + ....\344\272\244\346\233\277\347\273\204I.md" | 136 ++++++++++++++++++ .../Other-English-LearningNotes-SomeWords.md | 8 ++ tryGoPy/CHANGELOG.md | 111 ++++++++++++++ 9 files changed, 349 insertions(+) create mode 100644 Codes/0743-network-delay-time_20241125-half.cpp create mode 100644 Codes/3206-alternating-groups-i.cpp create mode 100644 Codes/3206-alternating-groups-i.go create mode 100644 Codes/3206-alternating-groups-i.java create mode 100644 Codes/3206-alternating-groups-i.py create mode 100644 "Solutions/LeetCode 3206.\344\272\244\346\233\277\347\273\204I.md" create mode 100644 tryGoPy/CHANGELOG.md diff --git a/Codes/0743-network-delay-time_20241125-half.cpp b/Codes/0743-network-delay-time_20241125-half.cpp new file mode 100644 index 000000000000..8e2f52e0a428 --- /dev/null +++ b/Codes/0743-network-delay-time_20241125-half.cpp @@ -0,0 +1,27 @@ +/* + * @Author: LetMeFly + * @Date: 2024-11-25 18:33:42 + * @LastEditors: LetMeFly.xyz + * @LastEditTime: 2024-11-25 18:39:53 + */ +#ifdef _WIN32 +#include "_[1,2]toVector.h" +#endif + +class Solution { +private: + void dfs(int root, vector& when) { + + } +public: + int networkDelayTime(vector>& times, int n, int k) { + vector>> graph(n + 1); // graph[i]: [i->a, i->b, i->c] + for (vector& thisRoad : times) { + graph[thisRoad[0]].push_back({thisRoad[1], thisRoad[2]}); + } + vector when(n + 1, 1e9); + when[0] = when[k] = 0; + dfs(k, when); + return *max_element(when.begin(), when.end()); + } +}; \ No newline at end of file diff --git a/Codes/3206-alternating-groups-i.cpp b/Codes/3206-alternating-groups-i.cpp new file mode 100644 index 000000000000..2c0e43ad2249 --- /dev/null +++ b/Codes/3206-alternating-groups-i.cpp @@ -0,0 +1,22 @@ +/* + * @Author: LetMeFly + * @Date: 2024-11-26 23:18:14 + * @LastEditors: LetMeFly.xyz + * @LastEditTime: 2024-11-26 23:18:20 + */ +#ifdef _WIN32 +#include "_[1,2]toVector.h" +#endif + +class Solution { +public: + int numberOfAlternatingGroups(vector& colors) { + int ans = 0; + for (int i = 0; i < colors.size(); i++) { + if (colors[i] != colors[(i + 1) % colors.size()] && colors[i] == colors[(i + 2) % colors.size()]) { + ans++; + } + } + return ans; + } +}; \ No newline at end of file diff --git a/Codes/3206-alternating-groups-i.go b/Codes/3206-alternating-groups-i.go new file mode 100644 index 000000000000..d497ec1c5978 --- /dev/null +++ b/Codes/3206-alternating-groups-i.go @@ -0,0 +1,16 @@ +/* + * @Author: LetMeFly + * @Date: 2024-11-26 23:35:39 + * @LastEditors: LetMeFly.xyz + * @LastEditTime: 2024-11-26 23:40:05 + */ +package main + +func numberOfAlternatingGroups(colors []int) (ans int) { + for i := range colors { + if colors[i] != colors[(i + 1) % len(colors)] && colors[i] == colors[(i + 2) % len(colors)] { + ans++ + } + } + return +} \ No newline at end of file diff --git a/Codes/3206-alternating-groups-i.java b/Codes/3206-alternating-groups-i.java new file mode 100644 index 000000000000..f412f2b2b128 --- /dev/null +++ b/Codes/3206-alternating-groups-i.java @@ -0,0 +1,17 @@ +/* + * @Author: LetMeFly + * @Date: 2024-11-26 23:22:57 + * @LastEditors: LetMeFly.xyz + * @LastEditTime: 2024-11-26 23:24:05 + */ +class Solution { + public int numberOfAlternatingGroups(int[] colors) { + int ans = 0; + for (int i = 0; i < colors.length; i++) { + if (colors[i] != colors[(i + 1) % colors.length] && colors[i] == colors[(i + 2) % colors.length]) { + ans++; + } + } + return ans; + } +} \ No newline at end of file diff --git a/Codes/3206-alternating-groups-i.py b/Codes/3206-alternating-groups-i.py new file mode 100644 index 000000000000..ae3b635f763a --- /dev/null +++ b/Codes/3206-alternating-groups-i.py @@ -0,0 +1,11 @@ +''' +Author: LetMeFly +Date: 2024-11-26 23:20:18 +LastEditors: LetMeFly.xyz +LastEditTime: 2024-11-26 23:20:28 +''' +from typing import List + +class Solution: + def numberOfAlternatingGroups(self, colors: List[int]) -> int: + return sum(colors[i] != colors[(i + 1) % len(colors)] != colors[(i + 2) % len(colors)] for i in range(len(colors))) \ No newline at end of file diff --git a/README.md b/README.md index 394f99e69629..a6af7727225d 100644 --- a/README.md +++ b/README.md @@ -717,6 +717,7 @@ |3192.使二进制数组全部等于1的最少操作次数II|中等|题目地址|题解地址|CSDN题解|LeetCode题解| |3194.最小元素和最大元素的最小平均值|简单|题目地址|题解地址|CSDN题解|LeetCode题解| |3200.三角形的最大高度|简单|题目地址|题解地址|CSDN题解|LeetCode题解| +|3206.交替组I|简单|题目地址|题解地址|CSDN题解|LeetCode题解| |3211.生成不含相邻零的二进制字符串|中等|题目地址|题解地址|CSDN题解|LeetCode题解| |3216.交换后字典序最小的字符串|简单|题目地址|题解地址|CSDN题解|LeetCode题解| |3222.求出硬币游戏的赢家|简单|题目地址|题解地址|CSDN题解|LeetCode题解| diff --git "a/Solutions/LeetCode 3206.\344\272\244\346\233\277\347\273\204I.md" "b/Solutions/LeetCode 3206.\344\272\244\346\233\277\347\273\204I.md" new file mode 100644 index 000000000000..77c2a0172f52 --- /dev/null +++ "b/Solutions/LeetCode 3206.\344\272\244\346\233\277\347\273\204I.md" @@ -0,0 +1,136 @@ +--- +title: 3206.交替组 I +date: 2024-11-26 23:43:43 +tags: [题解, LeetCode, 简单, 数组, 滑动窗口] +--- + +# 【LetMeFly】3206.交替组 I:遍历 + +力扣题目链接:[https://leetcode.cn/problems/alternating-groups-i/](https://leetcode.cn/problems/alternating-groups-i/) + +

给你一个整数数组 colors ,它表示一个由红色和蓝色瓷砖组成的环,第 i 块瓷砖的颜色为 colors[i] :

+ +
    +
  • colors[i] == 0 表示第 i 块瓷砖的颜色是 红色 。
  • +
  • colors[i] == 1 表示第 i 块瓷砖的颜色是 蓝色 。
  • +
+ +

环中连续 3 块瓷砖的颜色如果是 交替 颜色(也就是说中间瓷砖的颜色与它 左边 和 右边 的颜色都不同),那么它被称为一个 交替 组。

+ +

请你返回 交替 组的数目。

+ +

注意 ,由于 colors 表示一个  ,第一块 瓷砖和 最后一块 瓷砖是相邻的。

+ +

 

+ +

示例 1:

+ +
+

输入:colors = [1,1,1]

+ +

输出:0

+ +

解释:

+ +

+
+ +

示例 2:

+ +
+

输入:colors = [0,1,0,0,1]

+ +

输出:3

+ +

解释:

+ +

+ +

交替组包括:

+ +

+
+ +

 

+ +

提示:

+ +
    +
  • 3 <= colors.length <= 100
  • +
  • 0 <= colors[i] <= 1
  • +
+ + + +## 解题方法:遍历 + +遍历“三连砖”的起点: + +> 假设起点是$i$,那么下一个瓷砖就是$(i + 1) \% len(colors)$,下下个瓷砖就是$(i + 2) \% len(colors)$. + ++ 时间复杂度$O(len(colors))$ ++ 空间复杂度$O(1)$ + +### AC代码 + +#### C++ + +```cpp +class Solution { +public: + int numberOfAlternatingGroups(vector& colors) { + int ans = 0; + for (int i = 0; i < colors.size(); i++) { + if (colors[i] != colors[(i + 1) % colors.size()] && colors[i] == colors[(i + 2) % colors.size()]) { + ans++; + } + } + return ans; + } +}; +``` + +#### Python + +```python +from typing import List + +class Solution: + def numberOfAlternatingGroups(self, colors: List[int]) -> int: + return sum(colors[i] != colors[(i + 1) % len(colors)] != colors[(i + 2) % len(colors)] for i in range(len(colors))) +``` + +#### Java + +```java +class Solution { + public int numberOfAlternatingGroups(int[] colors) { + int ans = 0; + for (int i = 0; i < colors.length; i++) { + if (colors[i] != colors[(i + 1) % colors.length] && colors[i] == colors[(i + 2) % colors.length]) { + ans++; + } + } + return ans; + } +} +``` + +#### Go + +```go +package main + +func numberOfAlternatingGroups(colors []int) (ans int) { + for i := range colors { + if colors[i] != colors[(i + 1) % len(colors)] && colors[i] == colors[(i + 2) % len(colors)] { + ans++ + } + } + return +} +``` + +> 同步发文于CSDN和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2024/11/26/LeetCode%203206.%E4%BA%A4%E6%9B%BF%E7%BB%84I/)哦~ +> +> Tisfy:[https://letmefly.blog.csdn.net/article/details/144071026](https://letmefly.blog.csdn.net/article/details/144071026) diff --git a/Solutions/Other-English-LearningNotes-SomeWords.md b/Solutions/Other-English-LearningNotes-SomeWords.md index ebb1926b02fc..0ad59ba48da1 100644 --- a/Solutions/Other-English-LearningNotes-SomeWords.md +++ b/Solutions/Other-English-LearningNotes-SomeWords.md @@ -823,6 +823,14 @@ tags: [其他, 知识, 英语, Notes] ||| |walnut|n. 核桃,胡桃,胡桃木,胡桃色| |smack|v. 用巴掌打,掴,啪的一声使劲放(或扔、甩等),使劲碰(或撞)
n. 打巴掌,(打出的)一拳,啪的一声;海洛因
adv. 恰好,直接,不偏不倚地,猛地| +||| +|cafeteria|n. 自助餐厅| +||| +|antonym|n. 反义词| +|tare|n. 野豌豆,包装重量
v. 称皮重
tare weight: 皮重| +|Portuguese|adj. 葡萄牙的
n. 葡萄牙人,葡萄牙语| +|gratis|adj. 免费的
adv. 免费地,无偿的| +|limousine|n. 豪华轿车,大型高级轿车,(往返机场接送旅客的)中型客车|

单词收录总数

diff --git a/tryGoPy/CHANGELOG.md b/tryGoPy/CHANGELOG.md new file mode 100644 index 000000000000..2a3469eb5f6c --- /dev/null +++ b/tryGoPy/CHANGELOG.md @@ -0,0 +1,111 @@ +PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> git pull origin master +remote: Enumerating objects: 35, done. +remote: Counting objects: 100% (35/35), done. +remote: Compressing objects: 100% (17/17), done. +remote: Total 26 (delta 9), reused 25 (delta 9), pack-reused 0 (from 0) +Unpacking objects: 100% (26/26), 19.92 KiB | 4.00 KiB/s, done. +From github.com:LetMeFly666/LeetCode + * branch master -> FETCH_HEAD + 9e41c9485..6cb55b4a4 master -> origin/master +Updating 9e41c9485..6cb55b4a4 +Fast-forward + ...-the-count-of-numbers-which-are-not-special.cpp | 104 +++++++ + Codes/3238-find-the-number-of-winning-players.cpp | 58 ++++ + Codes/3238-find-the-number-of-winning-players.go | 26 ++ + Codes/3238-find-the-number-of-winning-players.java | 24 ++ + Codes/3238-find-the-number-of-winning-players.py | 14 + + KongMingQi.cpp | 3 +- + README.md | 4 +- + Solutions/LeetCode 3238.求出胜利玩家的数目.md | 176 ++++++++++++ + Solutions/Other-English-LearningNotes-SomeWords.md | 9 +- + Solutions/Other-Japanese-LearningNotes.md | 9 +- + Solutions/Other-Python-LearnPythonFrom0.md | 100 +++++++ + Solutions/Other-Verilog-Note.md | 2 + + history.del.html | 67 +++++ + history.del.ipynb | 238 ++++++++++++++++ + history.del.js | 68 +++++ + history.del2.js | 42 +++ + history.stillNeedREADME.del-视频压制.py | 305 +++++++++++++++++++++ + tryGo/JSFUZZ.bash | 19 -- + tryGo/chat-6yggde35y.bash | 118 -------- + temp-PythonTeaching.md => tryGo/temp-ZuiJin.md | 0 + tryGo/temp.2.html | 37 +++ + tryGo/temp.cssJianBian.html | 40 +++ + tryGo/tryEasyX.cpp | 17 -- + 24 files changed, 1381 insertions(+), 158 deletions(-) + create mode 100644 Codes/3233-find-the-count-of-numbers-which-are-not-special.cpp + create mode 100644 Codes/3238-find-the-number-of-winning-players.cpp + create mode 100644 Codes/3238-find-the-number-of-winning-players.go + create mode 100644 Codes/3238-find-the-number-of-winning-players.java + create mode 100644 Codes/3238-find-the-number-of-winning-players.py + create mode 100644 Solutions/LeetCode 3238.求出胜利玩家的数目.md + create mode 100644 Solutions/Other-Python-LearnPythonFrom0.md + create mode 100644 history.del.html + create mode 100644 history.del.ipynb + create mode 100644 history.del.js + create mode 100644 history.del2.js + create mode 100644 history.stillNeedREADME.del-视频压制.py + delete mode 100644 tryGo/JSFUZZ.bash + delete mode 100644 tryGo/chat-6yggde35y.bash + rename temp-PythonTeaching.md => tryGo/temp-ZuiJin.md (100%) + create mode 100644 tryGo/temp.2.html + create mode 100644 tryGo/temp.cssJianBian.html + delete mode 100644 tryGo/tryEasyX.cpp + create mode 100644 tryGo/tt.3.html +PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> cls^C +PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> git pull origin master +remote: Enumerating objects: 30, done. +remote: Counting objects: 100% (30/30), done. +remote: Compressing objects: 100% (18/18), done. +remote: Total 30 (delta 12), reused 29 (delta 12), pack-reused 0 (from 0) +Unpacking objects: 100% (30/30), 46.26 KiB | 19.00 KiB/s, done. +From github.com:LetMeFly666/LeetCode + * branch master -> FETCH_HEAD + 6cb55b4a4..37a4490d3 master -> origin/master +Updating 6cb55b4a4..37a4490d3 +Fast-forward + .gitignore | 1 + + ...allest-range-covering-elements-from-k-lists.cpp | 174 +++ + KongMingQi.cpp | 1287 -------------------- + README.md | 1 + + Solutions/LeetCode 0632.最小区间.md | 109 ++ + Solutions/Other-English-LearningNotes-SomeWords.md | 3 + + Solutions/Other-Japanese-LearningNotes.md | 1 + + Solutions/Other-Python-LearnPythonFrom0.md | 50 +- + history.del.html | 67 - + history.del.ipynb | 238 ---- + history.del.js | 68 -- + history.del2.js | 42 - + history.stillNeedREADME.del-视频压制.py | 305 ----- + tryGo/.gitkeep | 2 - + tryGo/temp.2.html | 37 - + tryGo/temp.cssJianBian.html | 40 - + tryGo/tt.3.html | 59 - + tryGoPy/.gitkeep | 2 + + {tryGo => tryGoPy}/OUT.md | 16 +- + tryGoPy/py1/README.md | 13 + + tryGoPy/py1/a.py | 8 + + tryGoPy/py1/b.py | 10 + + tryGo/temp-ZuiJin.md => tryGoPy/最近.md | 0 + {tryGo => tryGoPy}/本周周报.md | 34 +- + 24 files changed, 394 insertions(+), 2173 deletions(-) + create mode 100644 Codes/0632-smallest-range-covering-elements-from-k-lists.cpp + delete mode 100644 KongMingQi.cpp + create mode 100644 Solutions/LeetCode 0632.最小区间.md + delete mode 100644 history.del.html + delete mode 100644 history.del.ipynb + delete mode 100644 history.del.js + delete mode 100644 history.del2.js + delete mode 100644 history.stillNeedREADME.del-视频压制.py + delete mode 100644 tryGo/.gitkeep + delete mode 100644 tryGo/temp.2.html + delete mode 100644 tryGo/temp.cssJianBian.html + delete mode 100644 tryGo/tt.3.html + create mode 100644 tryGoPy/.gitkeep + rename {tryGo => tryGoPy}/OUT.md (86%) + create mode 100644 tryGoPy/py1/README.md + create mode 100644 tryGoPy/py1/a.py + create mode 100644 tryGoPy/py1/b.py + rename tryGo/temp-ZuiJin.md => tryGoPy/最近.md (100%) + rename {tryGo => tryGoPy}/本周周报.md (92%) +PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> \ No newline at end of file