2013年10月16日

3Sum

摘要: Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+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 in non-descending order. (ie,a≤b≤c)The solution set must not contain duplicate triplets. For example, given array S... 阅读全文

posted @ 2013-10-16 13:45 Step-BY-Step 阅读(147) 评论(0) 推荐(0) 编辑

Letter Combinations of a Phone Number

摘要: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", &q 阅读全文

posted @ 2013-10-16 08:06 Step-BY-Step 阅读(303) 评论(0) 推荐(0) 编辑

Remove Nth Node From End of List

摘要: Given a linked list, remove thenthnode 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 linked list becomes 1->2->3->5.Note:Givennwill always be valid.Try to do this in one pass.也可 阅读全文

posted @ 2013-10-16 08:05 Step-BY-Step 阅读(154) 评论(0) 推荐(0) 编辑

Valid Parentheses

摘要: 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 but"(]"and"([)]"are not. 1 阅读全文

posted @ 2013-10-16 08:03 Step-BY-Step 阅读(144) 评论(0) 推荐(0) 编辑

Generate Parentheses

摘要: Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))... 阅读全文

posted @ 2013-10-16 07:47 Step-BY-Step 阅读(143) 评论(0) 推荐(0) 编辑

Merge k Sorted Lists

摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity. 1 public class Solution { 2 public ListNode mergeKLists(ArrayList lists) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 if(lists.size()==0) r... 阅读全文

posted @ 2013-10-16 07:28 Step-BY-Step 阅读(137) 评论(0) 推荐(0) 编辑

Combination Sum II

摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number ... 阅读全文

posted @ 2013-10-16 03:31 Step-BY-Step 阅读(193) 评论(0) 推荐(0) 编辑

Swap Nodes in Pairs

摘要: Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant space. You maynotmodify the values in the list, only nodes itself can be changed. 1 public class Solut 阅读全文

posted @ 2013-10-16 01:31 Step-BY-Step 阅读(180) 评论(0) 推荐(0) 编辑

导航