摘要: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was inspired by this original tweet by Max Howell: Go 阅读全文
posted @ 2016-04-25 21:08 Black_Knight 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 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 a 阅读全文
posted @ 2016-04-25 20:58 Black_Knight 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l 阅读全文
posted @ 2016-04-25 20:36 Black_Knight 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l 阅读全文
posted @ 2016-04-25 20:22 Black_Knight 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 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 dept 阅读全文
posted @ 2016-04-25 20:05 Black_Knight 阅读(154) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort. 对链表使用插入排序还是很简单的,从链表中拆下一个节点,然后把它插入到已经排序的部分的链表中,直到所有节点都被插入。代码如下: 1 public class Solution { 2 public ListNode in 阅读全文
posted @ 2016-04-22 10:42 Black_Knight 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list in O(n log n) time using constant space complexity. 排序问题是我们遇到的一个老问题,从大一开始我们就学习了各种排序算法,大部分是基于数组的,比如冒泡排序,插入排序,快速排序等。这其中冒泡排序,插入排序的算法复杂 阅读全文
posted @ 2016-04-22 10:22 Black_Knight 阅读(190) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 涉及到二叉树的问题用递归的方法很容易理解。这个问题要求把一个升序排序的链表转换为 阅读全文
posted @ 2016-04-21 10:00 Black_Knight 阅读(203) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, flatten it to a linked list in-place. For example,Given The flattened tree should look like: 阅读全文
posted @ 2016-04-21 08:58 Black_Knight 阅读(160) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up:Can you 阅读全文
posted @ 2016-04-19 10:08 Black_Knight 阅读(180) 评论(0) 推荐(0) 编辑