<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>leetcode on Jeanphilo Blog</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/</link><description>Recent content in leetcode on Jeanphilo Blog</description><generator>Hugo -- 0.159.2</generator><language>zh-cn</language><lastBuildDate>Thu, 19 Mar 2026 13:18:26 +0800</lastBuildDate><atom:link href="https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/index.xml" rel="self" type="application/rss+xml"/><item><title>克隆图：哈希表 + DFS/BFS 实现无向图深拷贝（LeetCode 133）</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/133-clone-graph/</link><pubDate>Thu, 19 Mar 2026 13:18:26 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/133-clone-graph/</guid><description>用原节点到新节点的映射表实现无向连通图深拷贝，覆盖 DFS 与 BFS 两种写法、环处理、正确性分析与多语言可运行实现。</description></item><item><title>相同的树（Same Tree）同步递归 / BFS ACERS 解析</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/100-same-tree/</link><pubDate>Sun, 15 Mar 2026 21:29:42 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/100-same-tree/</guid><description>围绕 LeetCode 100 讲清同步递归比较、队列成对校验与结构等价判断，附工程迁移与多语言实现。</description></item><item><title>反转链表 II（Reverse Linked List II）哑节点+头插法 ACERS 解析</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/92-reverse-linked-list-ii/</link><pubDate>Tue, 10 Feb 2026 09:56:14 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/92-reverse-linked-list-ii/</guid><description>在单链表中仅反转区间 [left, right]：用哑节点定位前驱，再用头插法原地重排，时间 O(n)、额外空间 O(1)，附工程思路与多语言实现。</description></item><item><title>固定间距 1 检测：一次扫描判断 1 之间至少 k 个间隔（LeetCode 1437）</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/1437-check-if-all-ones-are-at-least-k-places-away/</link><pubDate>Thu, 22 Jan 2026 09:12:14 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/1437-check-if-all-ones-are-at-least-k-places-away/</guid><description>用一次扫描判断所有 1 之间是否至少相隔 k 个位置，含工程场景、常见误区与多语言实现。</description></item><item><title>判断一个数是否为 2 的幂（Power of Two）：位运算 O(1) ACERS 解析（LeetCode 231）</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/231-power-of-two/</link><pubDate>Wed, 21 Jan 2026 13:22:53 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/231-power-of-two/</guid><description>用位运算 O(1) 判断整数是否为 2 的幂，含工程场景、常见误区与多语言实现。</description></item><item><title>LeetCode 1456：最大元音子串数量的滑动窗口 ACERS 解析</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/1456-maximum-number-of-vowels-in-a-substring-of-given-length/</link><pubDate>Tue, 20 Jan 2026 13:40:45 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/1456-maximum-number-of-vowels-in-a-substring-of-given-length/</guid><description>用固定滑动窗口在 O(n) 时间求最大元音子串数量，含工程迁移与多语言实现。</description></item><item><title>LeetCode 1513：仅含 1 的子串数量（连续 1 子串计数）ACERS 解析</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/1513-number-of-substrings-with-only-ones/</link><pubDate>Sun, 18 Jan 2026 18:42:59 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/1513-number-of-substrings-with-only-ones/</guid><description>用连续段在线统计在 O(n) 时间计算仅含 1 的子串数量，含工程场景与多语言实现。</description></item><item><title>数据结构基础：好数对计数（Number of Good Pairs）哈希统计 ACERS 解析（LeetCode 1512）</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/1512-number-of-good-pairs/</link><pubDate>Tue, 30 Dec 2025 11:40:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/1512-number-of-good-pairs/</guid><description>用哈希计数一遍扫描解决好数对（Good Pairs）问题，附工程场景、复杂度对比与多语言实现。</description></item><item><title>咒语与药水的成功组合：排序 + 二分查找秒杀乘积约束问题（LeetCode 2300）</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/2300-successful-pairs-of-spells-and-potions/</link><pubDate>Thu, 04 Dec 2025 10:50:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/2300-successful-pairs-of-spells-and-potions/</guid><description>给定 spells 和 potions 两个数组以及 success 阈值，如何用排序 + 二分查找在 O((n+m)log m) 时间内求出每个咒语能与多少药水形成乘积 ≥ success 的成功组合，并给出多语言实现与工程应用示例。</description></item><item><title>固定长度子数组 + 至少 m 个不同元素：几乎唯一子数组的最大和（LeetCode 2841）</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/2841-maximum-sum-of-almost-unique-subarray/</link><pubDate>Thu, 04 Dec 2025 10:40:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/2841-maximum-sum-of-almost-unique-subarray/</guid><description>给定整数数组 nums 和正整数 m、k，要求在所有长度为 k、且至少包含 m 个不同元素的子数组中，找到最大和；若不存在返回 0。本文用滑动窗口 + 计数哈希表推导 O(n) 解法，并提供多语言实现与工程应用示例。</description></item><item><title>最少涂色次数拿到 k 个连续黑块：滑动窗口的极简解法（LeetCode 2379）</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/2379-minimum-recolors-to-get-k-consecutive-black-blocks/</link><pubDate>Thu, 04 Dec 2025 10:30:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/2379-minimum-recolors-to-get-k-consecutive-black-blocks/</guid><description>给定只包含 W/B 的字符串 blocks，每次可将一个 W 涂成 B，如何用一次线性扫描求出得到至少一次连续 k 个黑色块的最少操作次数，并给出多语言实现与工程应用示例。</description></item><item><title>一位与两位编码解析的刷题笔记与工程应用全解析（续集，LeetCode 717）</title><link>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/717-1-bit-and-2-bit-characters/</link><pubDate>Tue, 18 Nov 2025 23:43:17 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/zh/alg/leetcode/717-1-bit-and-2-bit-characters/</guid><description>&lt;h1 id="一位与两位编码解析的刷题笔记与工程应用全解析续集leetcode-717"&gt;&lt;strong&gt;一位与两位编码解析的刷题笔记与工程应用全解析（续集，LeetCode 717）&lt;/strong&gt;&lt;/h1&gt;
&lt;h2 id="副标题--摘要"&gt;&lt;strong&gt;副标题 / 摘要&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;本文解析 LeetCode《1-bit and 2-bit Characters》题目，讲解如何用简单的指针跳跃算法解析二进制编码序列，并展示该算法在通信协议、数据格式解析、事件流处理等工程场景中的真实应用。适合希望将算法题知识迁移到工程系统的开发者。&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="目标读者"&gt;&lt;strong&gt;目标读者&lt;/strong&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;刷 LeetCode、准备技术面试的开发者&lt;/li&gt;
&lt;li&gt;对通信协议、序列解析、数据流处理感兴趣的工程师&lt;/li&gt;
&lt;li&gt;想提升“抽象能力与工程迁移能力”的同学&lt;/li&gt;
&lt;li&gt;从事监控、序列分析、协议解析等工作的后端开发者&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="背景--动机为什么这题值得写一篇博客"&gt;&lt;strong&gt;背景 / 动机：为什么这题值得写一篇博客？&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;乍一看，这道题好像只是简单判断：&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;一个由 0/1 组成的编码流，最后一个 0 是否单独构成一个 1 位字符？&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;但本质上它对应的是 &lt;strong&gt;“变长编码（Variable-Length Coding）解析”&lt;/strong&gt;，而变长编码在工程中极其常见，比如：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;UTF-8 字符解析&lt;/li&gt;
&lt;li&gt;网络包头编码解析&lt;/li&gt;
&lt;li&gt;字节码指令流解析&lt;/li&gt;
&lt;li&gt;数据压缩（如 Huffman Coding）&lt;/li&gt;
&lt;li&gt;通信协议中的 Frame 解析&lt;/li&gt;
&lt;li&gt;行为序列中用跳表式结构编码的事件&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;因此，这道题不仅是算法题，更是“从左向右解析变长编码的模型题”。&lt;/p&gt;
&lt;p&gt;理解这题，就是理解大量系统底层的基础。&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="核心概念"&gt;&lt;strong&gt;核心概念&lt;/strong&gt;&lt;/h2&gt;
&lt;h3 id="1-变长编码variable-length-encoding"&gt;&lt;strong&gt;1. 变长编码（Variable-Length Encoding）&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;题目中规定了两种编码：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;1 位字符&lt;/strong&gt;：&lt;code&gt;0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;2 位字符&lt;/strong&gt;：&lt;code&gt;10&lt;/code&gt; 或 &lt;code&gt;11&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;这是一种简化的变长编码结构：字符长度取决于首位。&lt;/p&gt;
&lt;p&gt;工程中常见：&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;系统&lt;/th&gt;
&lt;th&gt;变长规则&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;UTF-8&lt;/td&gt;
&lt;td&gt;1~4 字节，根据前缀位判断长度&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TLV 协议&lt;/td&gt;
&lt;td&gt;T + 长度字段决定 Value 长度&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;字节码流&lt;/td&gt;
&lt;td&gt;opcode 决定后续参数个数&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;硬件指令集&lt;/td&gt;
&lt;td&gt;有变长和固定长度两类&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;题目正是这些系统的「极简模型」。&lt;/p&gt;</description></item></channel></rss>