2014年6月4日
摘要: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. ... 阅读全文
posted @ 2014-06-04 13:01 JessiaDing 阅读(97) 评论(0) 推荐(0) 编辑
  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) 编辑
  2014年5月23日
摘要: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid bu... 阅读全文
posted @ 2014-05-23 13:35 JessiaDing 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the lin... 阅读全文
posted @ 2014-05-23 12:03 JessiaDing 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in ... 阅读全文
posted @ 2014-05-23 11:34 JessiaDing 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly... 阅读全文
posted @ 2014-05-23 11:13 JessiaDing 阅读(120) 评论(0) 推荐(0) 编辑
  2014年5月22日
摘要: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be... 阅读全文
posted @ 2014-05-22 21:18 JessiaDing 阅读(134) 评论(0) 推荐(0) 编辑
摘要: Write a function to find the longest common prefix string amongst an array of strings. 要减少比较次数。在实现过程中我的想法是,2个2个比较,那么只要遍历一次数组就好。而且,在比较过程中,以较短的那个长度作为最大比较距离,较长的后半部分是不可能存在公共前缀的。 public class Soluti... 阅读全文
posted @ 2014-05-22 16:13 JessiaDing 阅读(114) 评论(0) 推荐(0) 编辑