乍一看没法获取上一个链表节点,似乎无法将当前结点去除。实际上只要将下一个节点的值覆盖当前节点,然后删除下一个节点就好了。注意这样不适用于尾节点。 代码 public class Solution { public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; } } Remove Linked List...
0155-min-stack.cpp 0160-intersection-of-two-linked-lists.cpp 0162-find-peak-element.cpp 0167-two-sum-ii-input-array-is-sorted.cpp 0169-majority-element.cpp 0179-largest-number.cpp 0187-repeated-dna-sequences.cpp 0189-rotate-array.cpp 0190-reverse-bits.cpp 0191-number-of-1-bits.cpp 0198-...
0225-Implement-Stack-using-Queues 0226-Invert-Binary-Tree 0227-Basic-Calculator-II 0230-Kth-Smallest-Element-in-a-BST 0232-Implement-Queue-using-Stacks 0234-Palindrome-Linked-List 0235-Lowest-Common-Ancestor-of-a-Binary-Search-Tree 0236-Lowest-Common-Ancestor-of-a-Bina...
/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */ bool insert(int val) { if(mp.count(val)) return false; mp[val] = nums.size(); nums.push_back(val); return true; ...