
LeetCode
美不胜收:-)
小白
展开
-
reorder-list
title: reorder-listdate: 2018-12-04 10:40:55categories: LeetCodetags: [List]题目描述:Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…You must do thi...原创 2018-12-04 12:00:59 · 148 阅读 · 0 评论 -
binary-tree-zigzag-level-order-traversal
描述:Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary ...原创 2018-12-17 21:29:46 · 139 阅读 · 0 评论 -
binary-tree-level-order-traversal
描述:Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \...原创 2018-12-17 21:48:27 · 220 阅读 · 0 评论 -
populating-next-right-pointers-in-each-node
描述:Given a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. If there is no next righ...原创 2018-12-11 23:19:38 · 137 阅读 · 0 评论 -
symmetric-tree
描述:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the followin...原创 2018-12-18 21:52:08 · 129 阅读 · 0 评论 -
reverse-linked-list-ii
题目描述:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL, m = 2 and n = 4,return1->4->3->2->5->NULL.注意事项...原创 2019-04-04 18:32:51 · 220 阅读 · 0 评论 -
partition-list
题目描述Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each ...原创 2019-04-04 18:53:31 · 178 阅读 · 0 评论 -
convert-sorted-list-to-binary-search-tree
题目描述Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思想找出中间节点,然后断开,构造出二分查找树代码一对于中间节点的处理:直接令成nullptr/** * Definition for singly-linked...原创 2019-03-31 22:53:59 · 187 阅读 · 0 评论 -
remove-duplicates-from-sorted-list.md
题目描述Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.思路:...原创 2019-04-06 21:15:18 · 262 阅读 · 0 评论 -
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 the nodes of the first two lists思路直接链起来就好代码/** * Definition for singly-linked list...原创 2019-04-06 21:19:26 · 163 阅读 · 0 评论 -
swap-nodes-in-pairs
题目描述Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only con...原创 2019-05-03 23:55:00 · 259 阅读 · 0 评论 -
merge-k-sorted-lists
题目描述Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路两两进行比较代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ...原创 2019-05-04 00:18:14 · 289 阅读 · 0 评论 -
remove-nth-node-from-end-of-li
题目描述Given a linked list, remove the n th node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node f...原创 2019-05-04 23:37:20 · 187 阅读 · 0 评论 -
binary-tree-maximum-path-sum
参考:链接:https://www.cnblogs.com/yuzhangcmu/p/4172855.htmlhttps://zxi.mytechroad.com/blog/tree/leetcode-124-binary-tree-maximum-path-sum/描述:题目描述Given a binary tree, find the maximum path sum.The pa...原创 2018-12-11 00:41:44 · 155 阅读 · 0 评论 -
construct-binary-tree-from-inorder-and-postorder-traversal
描述:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思想:就按照中序遍历和后序遍历建立二叉树C++代码:/** * Definition for binary...原创 2018-12-16 22:42:07 · 127 阅读 · 0 评论 -
insertion-sort-list
思路插入排序,维持两个链表,第一个原始链表,第二个排好序的链表。为了操作方便,第二个链表设置一个哑元dummy。当原始链表为空或者只有一个元素时,直接返回。如果不是,初始化dummy链表。每次从第一个链表中拿出一个元素来排序代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ...原创 2018-12-02 23:00:44 · 138 阅读 · 0 评论 -
Sort-List
C++:采用归并排序的方法思路:采用归并排序,首先要找到List的中间节点,然后一刀切开,分成L1,L2,然后递归即可。关键是怎么找到中间节点,我们设俩指针,slow,fast,slow滑动的步幅为一,fast滑动的步幅为二,这样,fast到末尾之后,slow指向中间节点。代码:/** * Definition for singly-linked list. * struct List...原创 2018-12-01 22:57:28 · 120 阅读 · 0 评论 -
copy-list-with-random-pointer
title: copy-list-with-random-pointerdate: 2018-12-09 00:27:33categories: LeetCodetags:[List]描述:A linked list is given such that each node contains an additional random pointer which could point ...原创 2018-12-09 00:53:28 · 211 阅读 · 0 评论 -
populating-next-right-pointers-in-each-node-ii
描述:Follow up for problem “Populating Next Right Pointers in Each Node”.What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra...原创 2018-12-13 00:40:35 · 205 阅读 · 0 评论 -
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 equals the given sum.For example:Given the below binary tree andsum...原创 2018-12-13 12:14:23 · 136 阅读 · 0 评论 -
title: binary-tree-postorder-traversal
描述Given a binary tree, return the postorder traversal of its nodes’ values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note: Recursive solution is trivial...原创 2018-12-03 23:31:10 · 122 阅读 · 0 评论 -
linked-list-cycle-ii
思路:这个说的挺好的链接代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public...原创 2018-12-06 23:40:20 · 159 阅读 · 0 评论 -
same-tree
描述:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.方法:就是简单的递归,...原创 2018-12-19 21:54:55 · 161 阅读 · 0 评论 -
path-sum-ii
描述:Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ ...原创 2018-12-15 00:42:14 · 283 阅读 · 0 评论 -
sum-root-to-leaf-numbers
描述:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total s...原创 2018-12-10 00:52:06 · 129 阅读 · 0 评论 -
balanced-binary-tree
描述:Given a binary tree, determine if it is height-balanced.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 diff...原创 2018-12-15 14:59:42 · 242 阅读 · 0 评论 -
binary-tree-level-order-traversal-ii
描述:Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, ...原创 2018-12-15 15:45:26 · 157 阅读 · 0 评论 -
remove-duplicates-from-sorted-list-ii
题目描述Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given1->2->3->3->4->4->5, return1-&g...原创 2019-05-16 21:50:45 · 269 阅读 · 0 评论