IncredibleThings

导航

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 28 下一页

2018年5月23日 #

LeetCode - Validate Binary Search Tree

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

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

LeetCode - Binary Tree Longest Consecutive Sequence

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

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

2018年5月21日 #

LeetCode - Kth Smallest Element in a BST

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

posted @ 2018-05-21 12:10 IncredibleThings 阅读(88) 评论(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 阅读(105) 评论(0) 推荐(0) 编辑

LeetCode - Median of Two Sorted Arrays

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

posted @ 2018-05-21 03:45 IncredibleThings 阅读(103) 评论(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 阅读(112) 评论(0) 推荐(0) 编辑

2018年5月20日 #

LeetCode - Evaluate Reverse Polish Notation

摘要: 用 stack 完美契合 阅读全文

posted @ 2018-05-20 22:44 IncredibleThings 阅读(89) 评论(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 阅读(103) 评论(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 阅读(91) 评论(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 阅读(82) 评论(0) 推荐(0) 编辑

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 28 下一页