上一页 1 ··· 6 7 8 9 10
摘要: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[2,4],[3,4],[2,3],[1,2],[1,3],[1,4] 1 public static List<List<int>> Combination(int n, int k) 2 { 3 List<List<int>>[] ret = new List<List. 阅读全文
posted @ 2012-07-09 22:12 ETCOW 阅读(393) 评论(0) 推荐(0) 编辑
摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1, a2, … ,a 阅读全文
posted @ 2012-07-03 23:41 ETCOW 阅读(633) 评论(7) 推荐(0) 编辑
摘要: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number of times.Note:All numbers (including target) will be positive integers.Elements in a combination (a1, a 阅读全文
posted @ 2012-07-03 22:54 ETCOW 阅读(739) 评论(0) 推荐(1) 编辑
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.e.g. "tea","and","ate","eat","dan". return"and","dan","tea","ate","eat"anangrams意思是重新排列 阅读全文
posted @ 2012-06-29 00:42 ETCOW 阅读(711) 评论(0) 推荐(0) 编辑
摘要: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?解法1 - 递归:1 public static int ClimbStairsRecursive(int n)2 {3 if (n <= 2)4 return n;5 ... 阅读全文
posted @ 2012-06-29 00:42 ETCOW 阅读(466) 评论(0) 推荐(0) 编辑
摘要: 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 1 class LinkedListNo 阅读全文
posted @ 2012-06-23 00:49 ETCOW 阅读(589) 评论(0) 推荐(0) 编辑
摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100". 1 public static string AddBinary(string a, string b) 2 { 3 try 4 { 5 int sum = Convert.ToInt32(a, 2) + Convert.ToInt32(b, 2); 6 ... 阅读全文
posted @ 2012-06-16 03:11 ETCOW 阅读(560) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must not contain duplicate quadruplets. . 阅读全文
posted @ 2012-06-15 22:26 ETCOW 阅读(627) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, find three integers inSsuch 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 one solution. For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is closest to th... 阅读全文
posted @ 2012-06-14 03:31 ETCOW 阅读(447) 评论(0) 推荐(0) 编辑
摘要: 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 @ 2012-06-13 00:10 ETCOW 阅读(1502) 评论(4) 推荐(1) 编辑
上一页 1 ··· 6 7 8 9 10