2014年4月2日

【LeetCode练习题】Remove Duplicates from Sorted List II

摘要: Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.题目意思:凡是给定链表里出现的重 阅读全文

posted @ 2014-04-02 21:45 Allen Blue 阅读(102) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Copy List with Random Pointer

摘要: Copy List with Random PointerA linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.题目意思:深拷贝一个给定的带random指针的链表,这个random指针可能会指向其他任意一个节点或者是为null。(又是链表啊啊啊啊啊啊啊!!!!!!!!Orz……)解题思路:在每个原来节点的后面插入一个新节点(la 阅读全文

posted @ 2014-04-02 21:38 Allen Blue 阅读(156) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Add Two Numbers

摘要: 链表相加You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Output:7 -> 0 -> 8题目意思:给定两个链表,返回其相加 阅读全文

posted @ 2014-04-02 17:54 Allen Blue 阅读(1069) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Permutations

摘要: 全排列Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].题目意思:给定一个集合,求全排列。解题思路:一般的话,有两种思路可以考虑。递归和DFS遍历树。这里我只用了递归的方法,关于怎么建一棵树然后DFS,可以参考 这里。这对于练习对递归的理解真是个不错的题目。以[1,2,3]举例,可以用纸笔画一画,分别以1,2,3为 阅读全文

posted @ 2014-04-02 16:43 Allen Blue 阅读(325) 评论(0) 推荐(0) 编辑

导航