Reverse every K-element Sub-list (medium) 7. Pattern: Tree Breadth First Search,树上的BFS类型 这种模式基于宽搜(Breadth First Search (BFS)),适用于需要遍历一颗树。借助于队列数据结构,从而能保证树的节点按照他们的层数打印出来。打印完当前层所有元素,才能执行到下一层。所有这种需要遍历树且需要一层一...
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 【解答】checkBalanced方法用来递归检查是否平衡的,返回树高度,偷了个巧,如果发现不平衡抛出TreeUnbalancedException异常: 1 2 3 4 5 6 ...
*/ public void dec(String key) { Item currentItem = this.map.get(key); if (currentItem == null) return; Item prev = currentItem.prev; currentItem.keys.remove(key); // remove the item if no key mapped to it if (currentItem.keys.isEmpty()) { this.link(prev, currentItem.next);...
2858.Minimum-Edge-Reversals-So-Every-Node-Is-Reachable (H-) 似树非树 823, 1902, Segment Tree 307.Range-Sum-Query-Mutable (H-) 1526.Minimum-Number-of-Increments-on-Subarrays-to-Form-a-Target-Array (H-) 1649.Create-Sorted-Array-through-Instructions (H-) 1157.Online-Majority-Element-In-...
Next Greater Node In Go Medium O(n) O(1) Linked List 1021. Remove Outermost Go Medium O(n) O(1) Parentheses 1047. Remove All Adjacent Go Medium O(n) O(1) Duplicates In String String Title Solution Difficulty Time Space 3. Longest Substring Without Go Medium O(n) O(1) Repeating ...
Remove Duplicates (easy) Squaring a Sorted Array (easy) Triplet Sum to Zero (medium) Triplet Sum Close to Target (medium) Triplets with Smaller Sum (medium) Subarrays with Product Less than a Target (medium) Dutch National Flag Problem (medium) ...
19Remove Nth Node From End of ListC 184Sum 17Letter Combinations of a Phone NumberC++ 163Sum Closest 153SumC++ 14Longest Common PrefixC 13Roman to IntegerC 12Integer to RomanC 11Container With Most Water 10Regular Expression Matching 9Palindrome NumberC ...
(node.y); if (currentVal == 1) { map.remove(node.y); } else { map.put(node.y, currentVal - 1); } // height==0 if (map.isEmpty()) { x = node.x; y = 0; result.add(new int[] { x, 0 }); } else { Integer last = (int) map.lastKey(); if (last != y) { ...
0019 Remove Nth Node From End of List Go 35.2% Medium 0020 Valid Parentheses Go 38.9% Easy 0021 Merge Two Sorted Lists Go 53.5% Easy 0022 Generate Parentheses Go 62.6% Medium 0023 Merge k Sorted Lists Go 40.2% Hard 0024 Swap Nodes in Pairs Go 50.3% Medium 0025 Reverse Nodes in...
null : next)* }* }*/functionremoveNthFromEnd(head:ListNode|null,n:number):ListNode|null{/**双指针,一个慢指针在快指针跑完的时候会指向需要删除的那一个节点为了解决一些删除头节点的情况,也就是n===head.size 构造一个 (-1,head)的链表,方便解决边界case还有一点,最后返回的不可以是快慢指针任一,...