随笔分类 - LeetCode
摘要:Binary Tree Preorder Traversal 题目链接 题目要求: Given a binary tree, return thepreordertraversal of its nodes' values. For example: Given binary tree{1...
阅读全文
摘要:Binary Tree Level Order Traversal 题目链接 题目要求: Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, lev...
阅读全文
摘要:题目链接 题目要求: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree i...
阅读全文
摘要:题目链接 题目要求: Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number. An example is the root-to-leaf pat...
阅读全文
摘要:题目链接 题目要求: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows:The left subtree of a nod...
阅读全文
摘要:Path Sum 题目链接 题目要求: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path ...
阅读全文
摘要:Symmetric Tree 题目链接 题目要求: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary ...
阅读全文
摘要:题目链接 题目要求: Sort a linked list inO(nlogn) time using constant space complexity. 满足O(nlogn)时间复杂度的有快排、归并排序、堆排序。在这里采用的是归并排序(空间复杂度O(logn)),具体程序如下: 1 /...
阅读全文
摘要:下边讨论暂不包括尾节点。 一般来说,我们要删除链表中的一个节点是需要知道其上一节点的。但我们真的需要吗? 其实我们可以将待删节点的下一节点的值和指向的下一节点赋予待删节点,然后删除待删节点的下一节点。具体示例程序如下: 1 //O(1)时间删除链表节点,从无头单链表中删除节点 2 void ...
阅读全文
摘要:题目链接 题目要求: Given a list, rotate the list to the right bykplaces, wherekis non-negative. For example: Given1->2->3->4->5->NULLandk=2, return4->5...
阅读全文
摘要:题目链接 题目要求: Given a linked list, reverse the nodes of a linked listkat a time and return its modified list. If the number of nodes is not a multip...
阅读全文
摘要:题目链接 题目要求: Given a linked list, remove thenthnode from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and ...
阅读全文
摘要:题目链接 题目要求: Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox. You should p...
阅读全文
摘要:1.Remove Duplicates from Sorted List 题目链接 题目要求: Given a sorted linked list, delete all duplicates such that each element appear onlyonce. For ex...
阅读全文
摘要:此题扩展:链表有环,如何判断相交? 参考资料: 编程判断两个链表是否相交 面试精选:链表问题集锦 题目链接 题目要求: Write a program to find the node at which the intersection of two singly linke...
阅读全文
摘要:题目链接 题目要求: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes co...
阅读全文
摘要:1.Merge Two Sorted Lists 题目链接 题目要求: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together t...
阅读全文
摘要:题目链接 题目要求: Given a singly linked listL:L0→L1→…→Ln-1→Ln, reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nod...
阅读全文
摘要:1.Linked List Cycle 题目链接 题目要求: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 刚看...
阅读全文
摘要:1.Reverse Linked List 题目链接 题目要求: Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you...
阅读全文