上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 43 下一页
摘要: Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"典型的递归。一步步构造字符串。当左括号出现次数 generateParenthesis(int n) { 3 // S 阅读全文
posted @ 2013-07-14 15:16 feiling 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 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.思路: 阅读全文
posted @ 2013-07-14 13:57 feiling 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 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.思路:两个指针,未能一次通过。。。。当需删除的元素是第一个元素时,直接按24-27进行删除 1 /** 2 * Defin 阅读全文
posted @ 2013-07-14 13:40 feiling 阅读(251) 评论(0) 推荐(0) 编辑
摘要: 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-07-11 23:22 feiling 阅读(315) 评论(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 @ 2013-07-04 11:41 feiling 阅读(256) 评论(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 ... 阅读全文
posted @ 2013-07-03 17:34 feiling 阅读(246) 评论(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 @ 2013-07-03 16:38 feiling 阅读(260) 评论(0) 推荐(0) 编辑
摘要: Write a function to find the longest common prefix string amongst an array of strings.方法1:BF, 首先计算两个字符串的prefix,每次用这个prefix与下一个字符串生成新的prefix效果较差,大数据集直接挂了,代码可读性太差-_-! 1 public String longestCommonPrefix(String[] strs) { 2 // Start typing your Java solution below 3 // DO NOT write main(... 阅读全文
posted @ 2013-06-27 20:11 feiling 阅读(1101) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.Note: You 阅读全文
posted @ 2013-06-27 16:32 feiling 阅读(327) 评论(0) 推荐(0) 编辑
摘要: Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. However, if you have solved 阅读全文
posted @ 2013-06-27 10:58 feiling 阅读(514) 评论(0) 推荐(0) 编辑
上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 43 下一页