Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c57b9c

Browse files
committed
Perfected707-design-linked-list.md.
1 parenta470714 commit1c57b9c

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

‎en/1-1000/349-intersection-of-two-arrays.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Each element in the result must be **unique** and you may return the result in *
2323

2424
##Intuition
2525
1. Convert one of the arrays to a`set`. The elements are unique in a`set`.
26-
2. When traversing the other array, ifthean element is found to already exist in the`set`, it means that the element belongs to the intersection, and the element should be added to the`results`.
26+
2. When traversing the other array, if an element is found to already exist in the`set`, it means that the element belongs to the intersection, and the element should be added to the`results`.
2727
3. The`results` is also of`set` type because duplicate removal is required.
2828

2929
##Complexity

‎en/1-1000/707-design-linked-list.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ If you want to use the doubly linked list, you will need one more attribute `pre
1414

1515
Implement the`MyLinkedList` class:
1616

17-
*`MyLinkedList()` Initializes the`MyLinkedList` object.
18-
*`int get(int index)` Get the value of the`index-th` node in the linked list. If the index is invalid, return`-1`.
19-
*`void addAtHead(int val)` Add a node of value`val` before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
20-
*`void addAtTail(int val)` Append a node of value`val` as the last element of the linked list.
21-
*`void addAtIndex(int index, int val)` Add a node of value`val` before the`index-th` node in the linked list. If`index` equals the length of the linked list, the node will be appended to the end of the linked list. If`index` is greater than the length, the node will**not be inserted**.
22-
*`void deleteAtIndex(int index)` Delete the`index-th` node in the linked list, if the index is valid.
17+
-`MyLinkedList()` Initializes the`MyLinkedList` object.
18+
-`int get(int index)` Get the value of the`index-th` node in the linked list. If the index is invalid, return`-1`.
19+
-`void addAtHead(int val)` Add a node of value`val` before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
20+
-`void addAtTail(int val)` Append a node of value`val` as the last element of the linked list.
21+
-`void addAtIndex(int index, int val)` Add a node of value`val` before the`index-th` node in the linked list. If`index` equals the length of the linked list, the node will be appended to the end of the linked list. If`index` is greater than the length, the node will**not be inserted**.
22+
-`void deleteAtIndex(int index)` Delete the`index-th` node in the linked list, if the index is valid.
2323

2424
###[Example 1]
2525
**Input**

‎zh/1-1000/707-design-linked-list.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ LeetCode link: [707. Design Linked List](https://leetcode.com/problems/design-li
55
[中文题解](#中文题解)
66

77
##LeetCode problem description
8-
Design your implementation of the linked list. You can choose to use a singly or doubly linked list.
8+
你可以选择使用单链表或者双链表,设计并实现自己的链表。
99

10-
A node in a singly linked list should have two attributes:`val`and`next`.`val`is the value of the current node, and`next`is a pointer/reference to the next node.
10+
单链表中的节点应该具备两个属性:`val``next``val`是当前节点的值,`next`是指向下一个节点的指针/引用。
1111

12-
If you want to use the doubly linked list, you will need one more attribute`prev`to indicate the previous node in the linked list. Assume all nodes in the linked list are**0-indexed**.
12+
如果是双向链表,则还需要属性`prev`以指示链表中的上一个节点。假设链表中的所有节点下标从 0 开始。
1313

14+
实现`MyLinkedList` 类:
1415

15-
Implement the`MyLinkedList` class:
16-
17-
*`MyLinkedList()` Initializes the`MyLinkedList` object.
18-
*`int get(int index)` Get the value of the`index-th` node in the linked list. If the index is invalid, return`-1`.
19-
*`void addAtHead(int val)` Add a node of value`val` before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
20-
*`void addAtTail(int val)` Append a node of value`val` as the last element of the linked list.
21-
*`void addAtIndex(int index, int val)` Add a node of value`val` before the`index-th` node in the linked list. If`index` equals the length of the linked list, the node will be appended to the end of the linked list. If`index` is greater than the length, the node will**not be inserted**.
22-
*`void deleteAtIndex(int index)` Delete the`index-th` node in the linked list, if the index is valid.
16+
-`MyLinkedList()` 初始化`MyLinkedList` 对象。
17+
-`int get(int index)` 获取链表中下标为`index` 的节点的值。如果下标无效,则返回`-1`
18+
-`void addAtHead(int val)` 将一个值为`val` 的节点插入到链表中第一个元素之前。在插入完成后,新节点会成为链表的第一个节点。
19+
-`void addAtTail(int val)` 将一个值为`val` 的节点追加到链表中作为链表的最后一个元素。
20+
-`void addAtIndex(int index, int val)` 将一个值为`val` 的节点插入到链表中下标为`index` 的节点之前。如果`index` 等于链表的长度,那么该节点会被追加到链表的末尾。如果 index 比长度更大,该节点将 不会插入 到链表中。
21+
-`void deleteAtIndex(int index)` 如果下标有效,则删除链表中下标为`index` 的节点。
2322

2423
###[Example 1]
2524
**Input**
@@ -38,16 +37,16 @@ Implement the `MyLinkedList` class:
3837
MyLinkedList myLinkedList=newMyLinkedList();
3938
myLinkedList.addAtHead(1);
4039
myLinkedList.addAtTail(3);
41-
myLinkedList.addAtIndex(1,2);//linked list becomes 1->2->3
42-
myLinkedList.get(1);//return 2
43-
myLinkedList.deleteAtIndex(1);//now the linked list is 1->3
44-
myLinkedList.get(1);//return 3
40+
myLinkedList.addAtIndex(1,2);//链表变为 1->2->3
41+
myLinkedList.get(1);//返回 2
42+
myLinkedList.deleteAtIndex(1);//现在,链表变为 1->3
43+
myLinkedList.get(1);//返回 3
4544
```
4645

4746
###[Constraints]
4847
-`0 <= index, val <= 1000`
49-
-Please do not use the built-inLinkedListlibrary.
50-
-At most`2000` calls will be made to`get`,`addAtHead`,`addAtTail`,`addAtIndex`and`deleteAtIndex`.
48+
-请不要使用内置的LinkedList库。
49+
-调用`get``addAtHead``addAtTail``addAtIndex``deleteAtIndex` 的次数不超过`2000`
5150

5251
##Intuition
5352
Before solving this problem, it is recommended to solve the simple problem[19. Remove Nth Node From End of List](19-remove-nth-node-from-end-of-list.md) first.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp