leetcode
weshjiness
这个作者很懒,什么都没留下…
展开
-
[leetcode]83 Remove Duplicates from Sorted List
题目大意:从有序链表中删除重复的元素,删除头指针。Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2原创 2015-02-04 14:38:04 · 335 阅读 · 0 评论 -
[leetcode]Populating Next Right Pointers in Each Node II
题目大意:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only原创 2015-04-05 15:50:28 · 324 阅读 · 0 评论 -
[leetcode]Binary Tree Postorder Traversal
题目分析:非递归实现对一颗树的后序遍历,可以用栈实现。贴一下思路:树根入栈;while(栈不空){if(栈顶节点有左儿子){栈顶节点左儿子入栈;原栈顶节点左儿子置空; } else if(栈顶节点有右儿子){ 栈顶节点右儿子入栈;原栈顶节点右儿子置空; }else{打印栈顶节点;弹栈;}}原创 2015-04-05 15:02:02 · 331 阅读 · 0 评论 -
[leetcode]142 Linked List Cycle II
题目大意:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space分析:这个题是对141 Linked List Cycle的升级原创 2015-02-09 14:13:37 · 387 阅读 · 0 评论 -
[leetcode]Populating Next Right Pointers in Each Node
题目大意:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its ne原创 2015-04-05 15:44:44 · 282 阅读 · 0 评论 -
[leetcode]Binary Tree Preorder Traversal
题目分析:非递归实现对一颗树的先序遍历,可以用栈实现。贴一下思路:树根如栈;打印树根元素;while(栈不空){ if(栈顶节点有左儿子){ 打印栈顶节点左儿子; 栈顶节点左儿子入栈; 栈顶节点左儿子置空; //一定要置空 } else if(栈顶节点有右儿子){原创 2015-04-04 21:05:43 · 355 阅读 · 0 评论 -
[leetcode]Binary Tree Inorder Traversal
题目分析:非递归实现对一颗树的中序遍历,可以用栈实现。贴一下思路:打印树根元素;while(栈不空){if(栈顶节点有左儿子){栈顶节点左儿子入栈;栈顶节点左儿子置空; } else if(栈顶节点有右儿子){ 打印栈顶节点;弹栈;弹栈前的栈顶节点右儿子入栈; }else{打印栈顶节点;弹栈;}}原创 2015-04-04 21:26:16 · 328 阅读 · 0 评论 -
[leetcode]21 Merge Two Sorted Lists
题目大意:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.分析:第一种方法可以直接new一个新的链表,对两个链表同时进行循环,比较两个链表头指针的元素大小,小原创 2015-02-08 14:26:16 · 331 阅读 · 0 评论 -
[leetcode]82 Remove Duplicates from Sorted List II
题目大意:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.原创 2015-02-06 14:42:02 · 442 阅读 · 0 评论 -
[leetcode]141 Linked List Cycle
题目大意:链表判断是否有环分析:设置两个指针A,B,起始位置在头节点,A每次走一步,B每次走两步,如果A,B值有相等的时候,既有环,需要注意一下边界条件处理。原创 2015-02-04 13:59:05 · 366 阅读 · 0 评论 -
[leetcode]136 Single Number
题目大意:一个数组,里面除了一个数之外,其他所有数都是出现两次,找出那个特殊的数。分析:题目有要求,复杂度是o(n),而且不能再用额外的空间,可以利用异或,从第一个数一直异或到最后一个,结果就是那个特殊的数。原创 2015-02-02 13:32:58 · 352 阅读 · 0 评论 -
[leetcode]Convert Sorted List to Binary Search Tree
题目大意:将一个有序链表转化为一颗平衡二叉树题目分析:用递归和二分实现,可以将创建树的过程视为中序遍历一棵树的逆过程(链表即为中序遍历二叉树的结果。)。中序遍历时,首先要访问最左下的叶节点,那就首先创建该节点,然后创建它的父节点,再创建它的兄弟右节点。注意:要首先求出链表的长度,以便于二分地递归。原创 2015-04-12 20:29:41 · 577 阅读 · 0 评论