IncredibleThings

导航

05 2018 档案

LeetCode - Validate Binary Search Tree
摘要:如果对BST 中序遍历, 会产生有序数列。 非递归法: 二刷, 根据二叉树原理进行递归: 阅读全文

posted @ 2018-05-23 11:53 IncredibleThings 阅读(114) 评论(0) 推荐(0)

LeetCode - Binary Tree Longest Consecutive Sequence
摘要:Recursion: 时间O(n) 空间O(h) 因为要找最长的连续路径,我们在遍历树的时候需要两个信息,一是目前连起来的路径有多长,二是目前路径的上一个节点的值。我们通过递归把这些信息代入,然后通过返回值返回一个最大的就行了。 阅读全文

posted @ 2018-05-23 11:16 IncredibleThings 阅读(89) 评论(0) 推荐(0)

LeetCode - Kth Smallest Element in a BST
摘要:那么这道题给的提示是让我们用BST的性质来解题,最重要的性质是就是左<根<右,那么如果用中序遍历所有的节点就会得到一个有序数组。所以解题的关键还是中序遍历啊。 阅读全文

posted @ 2018-05-21 12:10 IncredibleThings 阅读(97) 评论(0) 推荐(0)

LeetCode - LRU Cache
摘要:此题的思路是运用hashmap和double linked nodes The hash makes the time of get() to be O(1). The list of double linked nodes make the nodes adding/removal operati 阅读全文

posted @ 2018-05-21 10:42 IncredibleThings 阅读(109) 评论(0) 推荐(0)

LeetCode - Median of Two Sorted Arrays
摘要:题目要求time complexity 是O(log (m+n)), 先归并排序也是不可行的, 时间复杂度为O(m+n) 阅读全文

posted @ 2018-05-21 03:45 IncredibleThings 阅读(108) 评论(0) 推荐(0)

LeetCode - Word Ladder
摘要:Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, 阅读全文

posted @ 2018-05-21 01:16 IncredibleThings 阅读(119) 评论(0) 推荐(0)

LeetCode - Evaluate Reverse Polish Notation
摘要:用 stack 完美契合 阅读全文

posted @ 2018-05-20 22:44 IncredibleThings 阅读(95) 评论(0) 推荐(0)

LeetCode - Reverse Words in a String II
摘要:Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters. The input string does not contain lea 阅读全文

posted @ 2018-05-20 10:44 IncredibleThings 阅读(108) 评论(0) 推荐(0)

LeetCode - Rotate Array
摘要:Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Example 2: Note: Try to come up as many solutions as you 阅读全文

posted @ 2018-05-20 08:08 IncredibleThings 阅读(97) 评论(0) 推荐(0)

LeetCode - Spiral Matrix II
摘要:Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. Example: Input: 3 Output: [ [ 1, 2, 3 ], [ 8, 阅读全文

posted @ 2018-05-20 02:39 IncredibleThings 阅读(88) 评论(0) 推荐(0)

LeetCode - Spiral Matrix
摘要:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example 1: Example 2: 复杂度 时间 O(NM) 空间 O(1) 思路 阅读全文

posted @ 2018-05-20 00:48 IncredibleThings 阅读(249) 评论(0) 推荐(0)

Sort An Unsorted Stack
摘要:Given a stack of integers, sort it in ascending order using another temporary stack. Examples: 阅读全文

posted @ 2018-05-17 09:22 IncredibleThings 阅读(129) 评论(0) 推荐(0)

LeetCode - Sum of Left Leaves
摘要:Find the sum of all left leaves in a given binary tree. Example: 阅读全文

posted @ 2018-05-11 11:23 IncredibleThings 阅读(99) 评论(0) 推荐(0)