Skip to content

Commit ee3e558

Browse files
committed
feat: change git push rules
1 parent 84e9374 commit ee3e558

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
yarn.lock
3-
.idea
3+
.idea
4+
5+
# src/*

common/resources/store.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"today":"2182","today-question-info":{"id":"83","enName":"remove-duplicates-from-sorted-list","title":"删除排序链表中的重复元素","detail":"<p>给定一个已排序的链表的头<meta charset=\"UTF-8\" />&nbsp;<code>head</code>&nbsp;,&nbsp;<em>删除所有重复的元素,使每个元素只出现一次</em>&nbsp;。返回 <em>已排序的链表</em>&nbsp;。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/01/04/list1.jpg\" style=\"height: 160px; width: 200px;\" />\n<pre>\n<strong>输入:</strong>head = [1,1,2]\n<strong>输出:</strong>[1,2]\n</pre>\n\n<p><strong>示例 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/01/04/list2.jpg\" style=\"height: 123px; width: 300px;\" />\n<pre>\n<strong>输入:</strong>head = [1,1,2,3,3]\n<strong>输出:</strong>[1,2,3]\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li>链表中节点数目在范围 <code>[0, 300]</code> 内</li>\n\t<li><code>-100 &lt;= Node.val &lt;= 100</code></li>\n\t<li>题目数据保证链表已经按升序 <strong>排列</strong></li>\n</ul>\n","date":"2024-01-14","jsCode":"/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicates = function(head) {\n\n};"},"today-tag":"83"}
1+
{"today":"2182","today-question-info":{"id":"82","enName":"remove-duplicates-from-sorted-list-ii","title":"删除排序链表中的重复元素 II","detail":"<p>给定一个已排序的链表的头&nbsp;<code>head</code> ,&nbsp;<em>删除原始链表中所有重复数字的节点,只留下不同的数字</em>&nbsp;。返回 <em>已排序的链表</em>&nbsp;。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/01/04/linkedlist1.jpg\" style=\"height: 142px; width: 500px;\" />\n<pre>\n<strong>输入:</strong>head = [1,2,3,3,4,4,5]\n<strong>输出:</strong>[1,2,5]\n</pre>\n\n<p><strong>示例 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/01/04/linkedlist2.jpg\" style=\"height: 164px; width: 400px;\" />\n<pre>\n<strong>输入:</strong>head = [1,1,1,2,3]\n<strong>输出:</strong>[2,3]\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li>链表中节点数目在范围 <code>[0, 300]</code> 内</li>\n\t<li><code>-100 &lt;= Node.val &lt;= 100</code></li>\n\t<li>题目数据保证链表已经按升序 <strong>排列</strong></li>\n</ul>\n","date":"2024-01-15","jsCode":"/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicates = function(head) {\n\n};"},"today-tag":"82"}

src/82/index.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const { withTimeLog } = require("../../common/utils/withTimeLog");
2+
/**
3+
* 82.删除排序链表中的重复元素 II [2024-01-15]
4+
* 给定一个已排序的链表的头 head , 删除原始链表中所有重复数字的节点,只留下不同的数字 。返回 已排序的链表 。
5+
*
6+
* 示例 1:
7+
* 输入:head = [1,2,3,3,4,4,5]
8+
* 输出:[1,2,5]
9+
* 示例 2:
10+
* 输入:head = [1,1,1,2,3]
11+
* 输出:[2,3]
12+
*
13+
* 提示:
14+
* 链表中节点数目在范围 [0, 300] 内
15+
* -100 <= Node.val <= 100
16+
* 题目数据保证链表已经按升序 排列
17+
*
18+
*/
19+
/**
20+
* Definition for singly-linked list.
21+
* function ListNode(val, next) {
22+
* this.val = (val===undefined ? 0 : val)
23+
* this.next = (next===undefined ? null : next)
24+
* }
25+
*/
26+
/**
27+
* @param {ListNode} head
28+
* @return {ListNode}
29+
*/
30+
// 定义一个函数,用于删除链表中的重复节点
31+
var deleteDuplicates = function(head) {
32+
// 创建一个虚拟节点,指向head
33+
let dummy = new ListNode(-1, head);
34+
// 定义一个变量,用于记录前一个节点
35+
let prev = dummy;
36+
// 定义一个变量,用于记录当前节点
37+
let cur = head;
38+
// 遍历链表
39+
while (cur) {
40+
// 定义一个变量,用于记录下一个节点
41+
let next = cur.next;
42+
// 如果下一个节点存在,且下一个节点的值和当前节点的值相等
43+
if (next && next.val === cur.val) {
44+
// 找到最后一个重复的节点,并记录
45+
while (next && next.val === cur.val) {
46+
next = next.next;
47+
}
48+
// 将前一个节点的指针指向最后一个重复的节点
49+
prev.next = next;
50+
// 将当前节点指向最后一个重复的节点
51+
cur = next;
52+
} else {
53+
// 如果下一个节点和当前节点值不相等,则将前一个节点指向当前节点,当前节点指向下一个节点
54+
prev = cur;
55+
cur = cur.next;
56+
}
57+
}
58+
// 返回虚拟节点的下一个节点
59+
return dummy.next;
60+
};
61+
62+
/**
63+
* Test case
64+
*/
65+
withTimeLog(() => deleteDuplicates(head = [1,2,3,3,4,4,5]),[1,2,5]);
66+
withTimeLog(() => deleteDuplicates(head = [1,1,1,2,3]),[2,3]);
67+
68+
console.log("点击跳转到题目提交:https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/")
69+

0 commit comments

Comments
 (0)