You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/1-1000/349-intersection-of-two-arrays.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ Each element in the result must be **unique** and you may return the result in *
23
23
24
24
##Intuition
25
25
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`.
27
27
3. The`results` is also of`set` type because duplicate removal is required.
*`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.
-`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.
Design your implementation of the linked list. You can choose to use a singly or doubly linked list.
8
+
你可以选择使用单链表或者双链表,设计并实现自己的链表。
9
9
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.
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**.
*`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.
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.