上一页 1 ··· 7 8 9 10 11 12 下一页
摘要: 原题地址:http://oj.leetcode.com/problems/balanced-binary-tree/题意:判断一颗二叉树是否是平衡二叉树。解题思路:在这道题里,平衡二叉树的定义是二叉树的任意节点的两颗子树之间的高度差小于等于1。这实际上是AVL树的定义。首先要写一个计算二叉树高度的函... 阅读全文
posted @ 2014-05-10 10:54 南郭子綦 阅读(5726) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/题意:根据二叉树的先序遍历和中序遍历恢复二叉树。解题思路:可以参照http://www.cnblogs.com... 阅读全文
posted @ 2014-05-10 10:40 南郭子綦 阅读(2234) 评论(1) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/题意:根据二叉树的中序遍历和后序遍历恢复二叉树。解题思路:看到树首先想到要用递归来解题。以这道题为例:如果一... 阅读全文
posted @ 2014-05-10 10:34 南郭子綦 阅读(3099) 评论(2) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/single-number-ii/题意:Given an array of integers, every element appearsthreetimes except for one. Find that single ... 阅读全文
posted @ 2014-05-09 22:38 南郭子綦 阅读(4111) 评论(1) 推荐(0) 编辑
摘要: 原题地址:http://www.cnblogs.com/x1957/p/3373994.html题意:Given an array of integers, every element appearstwiceexcept for one. Find that single one.要求:线性时间复... 阅读全文
posted @ 2014-05-09 20:23 南郭子綦 阅读(4627) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/valid-number/题意:判断输入的字符串是否是合法的数。解题思路:这题只能用确定有穷状态自动机(DFA)来写会比较优雅。本文参考了http://blog.csdn.net/kenden23/article/detail... 阅读全文
posted @ 2014-05-01 19:49 南郭子綦 阅读(4415) 评论(1) 推荐(4) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/题意:Given a linked list, remove thenthnode from the end of list and return its he... 阅读全文
posted @ 2014-04-30 18:42 南郭子綦 阅读(4893) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/swap-nodes-in-pairs/题意:将链表中的节点两两交换。Given1->2->3->4, you should return the list as2->1->4->3.解题思路:这题主要涉及到链表的操作,没什么... 阅读全文
posted @ 2014-04-30 18:10 南郭子綦 阅读(3242) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/linked-list-cycle-ii/题意:如果链表中存在环路,找到环路的起点节点。解题思路:这道题有点意思。首先使用快慢指针技巧,如果fast指针和slow指针相遇,则说明链表存在环路。具体技巧参见上一篇http://w... 阅读全文
posted @ 2014-04-30 17:46 南郭子綦 阅读(3961) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/linked-list-cycle/题意:判断链表中是否存在环路。解题思路:快慢指针技巧,slow指针和fast指针开始同时指向头结点head,fast每次走两步,slow每次走一步。如果链表不存在环,那么fast或者fast... 阅读全文
posted @ 2014-04-30 16:33 南郭子綦 阅读(4210) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/lru-cache/题意:设计LRU Cache参考文献:http://blog.csdn.net/hexinuaa/article/details/6630384 这篇博文总结的很到位。 https://github... 阅读全文
posted @ 2014-04-30 16:15 南郭子綦 阅读(7250) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/reorder-list/题意:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this... 阅读全文
posted @ 2014-04-30 10:59 南郭子綦 阅读(3321) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/insertion-sort-list/题意:对链表进行插入排序。解题思路:首先来对插入排序有一个直观的认识,来自维基百科。 代码循环部分图示:代码:class Solution:# @p... 阅读全文
posted @ 2014-04-29 21:13 南郭子綦 阅读(3461) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/sort-list/题意:链表的排序。要求:时间复杂度O(nlogn),空间复杂度O(1)。解题思路:由于题目对时间复杂度和空间复杂度要求比较高,所以查看了各种解法,最好的解法就是归并排序,由于链表在归并操作时并不需要像数组的... 阅读全文
posted @ 2014-04-29 16:23 南郭子綦 阅读(4822) 评论(0) 推荐(0) 编辑
摘要: 原题地址:http://oj.leetcode.com/problems/3sum-closest/题意:数组中每三个元素进行求和,找出所有和中大小最接近target的和,并返回这个和与target之间的差值。解题思路:使用一个变量mindiff来监测和与target之间的差值,如果差值为0,直接返... 阅读全文
posted @ 2014-04-29 16:06 南郭子綦 阅读(3803) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 下一页