2014年5月27日
摘要: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. Yo... 阅读全文
posted @ 2014-05-27 16:53 JessiaDing 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 对每一个排序链表都设置一个指针。每次讲指针指向的单元中最小值链接,直到所有指针为空。 public class Solution { public ListNode merg... 阅读全文
posted @ 2014-05-27 15:38 JessiaDing 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 刚看到题目的时候,有点不知所措。网上很多递归的方法,看完以后是心存疑虑的。 我的想法是,n对Parentheses,假设n-1的已经得到,如何在n-1的结果中添加一对有效括号呢。 其实可以把n-1拆成k和n-1-k,这样每次在k最外面添加一队这样的到的n对的有效序列。 k值是从0取到n-1. 其实左边就是一对,2对…到n-1对. 再把左边和右边添加在一起就是一个有效对。 特殊值是k==... 阅读全文
posted @ 2014-05-27 13:48 JessiaDing 阅读(98) 评论(0) 推荐(0) 编辑