0701-0710

701. Insert into a Binary Search Tree $\star\star$

702. Search in a Sorted Array of Unknown Size $\star\star$

703. Kth Largest Element in a Stream $\star$

704. Binary Search $\star$

705. Design HashSet $\star$

706. Design HashMap $\star$

707. Design Linked List $\star\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class MyLinkedList {
 public:
  MyLinkedList() : length(0) { head = new ListNode(0); }

  int get(int index) {
    if (index < 0 || index >= length) return -1;
    ListNode* curr = head->next;
    for (int i = 0; i < index; ++i) curr = curr->next;
    return curr->val;
  }

  void addAtHead(int val) {
    ListNode* curr = head->next;
    head->next = new ListNode(val);
    head->next->next = curr;
    ++length;
  }

  void addAtTail(int val) {
    ListNode* curr = head;
    while (curr->next) curr = curr->next;
    curr->next = new ListNode(val);
    ++length;
  }

  void addAtIndex(int index, int val) {
    if (index > length) return;
    ListNode* curr = head;
    for (int i = 0; i < index; ++i) curr = curr->next;
    ListNode* temp = curr->next;
    curr->next = new ListNode(val);
    curr->next->next = temp;
    ++length;
  }

  void deleteAtIndex(int index) {
    if (index < 0 || index >= length) return;
    ListNode* curr = head;
    for (int i = 0; i < index; ++i) curr = curr->next;
    ListNode* temp = curr->next;
    curr->next = temp->next;
    --length;
    delete temp;
  }

 private:
  struct ListNode {
    int val;
    ListNode* next;
    ListNode(int x) : val(x), next(nullptr) {}
  };

  int length;
  ListNode* head;
};

708. Insert into a Sorted Circular Linked List $\star\star$

709. To Lower Case $\star$

710. Random Pick with Blacklist $\star\star\star$