摘要: 105. Construct Binary Tree from Preorder and Inorder Traversal 题目链接:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-trav 阅读全文
posted @ 2017-04-22 07:35 小谷子的博客园 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 5. Longest Palindromic Substring 题目链接:https://leetcode.com/problems/longest-palindromic-substring/#/description 题目大意:给定一个字符串s,返回该字符串的最长回文子串。s的最大长度不超过1 阅读全文
posted @ 2017-04-15 09:07 小谷子的博客园 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 78. Subsets 题目链接:https://leetcode.com/problems/subsets/#/description 题目大意:给定一个整数集合,所有的整数都不相等,要求返回所有可能的子集。 题目思路:排列组合问题,集合中的任意元素,都能产生两类子集,一类包含该元素,一类不包含该 阅读全文
posted @ 2017-04-10 19:37 小谷子的博客园 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 226. Invert Binary Tree 题目链接:https://leetcode.com/problems/invert-binary-tree/#/description 题目大意:反转一棵二叉树 思路:递归反转左子树和右子树,然后再交换左子树和右子树的根节点即可。 算法复杂度分析:时间 阅读全文
posted @ 2017-04-01 13:41 小谷子的博客园 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 146. LRU Cache 题目链接:https://leetcode.com/problems/lru-cache/#/description 题目大意:为最近最少访问cache设计和实现一个数据结构,该数据结构应该支持get和put操作。 get(key) - Get the value (w 阅读全文
posted @ 2017-03-26 21:40 小谷子的博客园 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 148. Sort List 题目链接:https://leetcode.com/problems/sort-list/#/description 题目大意:给定一个链表,要求以O(nlogn)时间复杂度和O(1)空间复杂度将链表排序。 思路:使用归并排序 算法步骤:(1)使用快慢指针将链表分为两部 阅读全文
posted @ 2017-03-21 16:57 小谷子的博客园 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 56. Merge Intervals 题目链接:https://leetcode.com/problems/merge-intervals/#/description 题目大意:给定区间的集合,合并所有有重叠的区间,然后返回合并区间后的集合 思路:A和B两个区间合并的条件A.start <= B. 阅读全文
posted @ 2017-03-18 16:52 小谷子的博客园 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 题目链接:https://leetcode.com/problems/restore-ip-addresses/?tab=Description 题目大意:给定一个字符串,字符串只包含数字,要求返回所以合法的IP地址组合。 思路:IP地址由四个字节组成,每个字节表示的整数范围为0-255,所以需要把 阅读全文
posted @ 2017-03-10 22:14 小谷子的博客园 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 35. Search Insert Position 题目链接:https://leetcode.com/problems/search-insert-position/?tab=Description 题目大意:给定一个有序数组和一个目标值,如果目标值在数组中,则返回其所在的位置,如果不存在,则返 阅读全文
posted @ 2017-03-05 23:06 小谷子的博客园 阅读(242) 评论(0) 推荐(0) 编辑
摘要: 题目链接:https://leetcode.com/problems/kth-largest-element-in-an-array/?tab=Description 题目大意:给定一个未排序的数组,找出数组中第k大的数。举个例子数组nums为[3,2,1,5,6,4],k=2,则返回5. 思路:( 阅读全文
posted @ 2017-02-27 15:46 小谷子的博客园 阅读(137) 评论(0) 推荐(0) 编辑