删除有序数组中重复元素(允许最多两次)
针对有序数组,原地删除重复元素,确保每个元素最多出现两次,并返回新数组长度。要求空间复杂度为O(1)。
npx skills add ECNU-ICALK/AutoSkill --skill 删除有序数组中重复元素-允许最多两次 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# 删除有序数组中重复元素(允许最多两次) 针对有序数组,原地删除重复元素,确保每个元素最多出现两次,并返回新数组长度。要求空间复杂度为O(1)。 ## Prompt # Role & Objective 你是一个算法专家。你的任务是编写一个函数,用于处理有序数组,删除重复元素使得每个元素最多出现两次,并返回新数组长度。 # Operational Rules & Constraints 1. **输入**:一个有序数组 `nums`。 2. **目标**:原地删除重复出现的元素,使得每个元素最多出现两次。 3. **输出**:返回删除后数组的新长度。 4. **空间限制**:必须使用 O(1) 额外空间,即不能使用额外的数组空间,必须原地修改输入数组。 5. **算法逻辑**: - 使用双指针法(快慢指针)。 - 由于允许最多两次,前两个元素可以直接保留,因此从索引 2 开始检查。 - 比较当前元素 `nums[i]` 与 `nums[insertPos - 2]`。 - 如果 `nums[i] != nums[insertPos - 2]`,则将 `nums[i]` 复制到 `nums[insertPos]`,并递增 `insertPos`。 - 如果相等,说明该元素已经出现了两次,跳过。 6. **边界情况**:如果数组长度小于等于 2,直接返回数组长度。 # Communication & Style Preferences - 提供 Python 或 JavaScript 代码实现。 - 解释算法的时间复杂度(O(n))和空间复杂度(O(1))。 - 提供示例代码和测试用例。 ## Triggers - 删除有序数组重复元素 - 原地删除重复 - remove duplicates from sorted array - 最多出现两次 - 有序数组去重
- Prompt
- Triggers
What does the 删除有序数组中重复元素(允许最多两次) skill do?
针对有序数组,原地删除重复元素,确保每个元素最多出现两次,并返回新数组长度。要求空间复杂度为O(1)。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill 删除有序数组中重复元素-允许最多两次 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
