public class Solution { public String reverseWords(String s) { if(s==null||s.length()==0) return ""; s=reverse(s); Strin...
分类:
其他好文 时间:
2014-09-06 22:32:43
阅读次数:
278
在1 - 10 中,求出 7 个数的排列组合。出现了超时,而超时的原因是有好多重复情况,复杂度上来说,和答案的复杂度是一样的,但是答案中重复了太多了,体会下。超时1:class Solution {public: vector > combine(int n, int k) { ...
分类:
其他好文 时间:
2014-09-06 22:28:03
阅读次数:
363
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((...
分类:
其他好文 时间:
2014-09-06 16:05:23
阅读次数:
182
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:不断将相邻的链表两两合并,知道只剩一个链表为止。 1 class Solution { 2 pub...
分类:
其他好文 时间:
2014-09-06 14:51:13
阅读次数:
172
public class Solution { public List generateParenthesis(int n) { List result = new ArrayList(); Stack numStack = new Stack(); ...
分类:
其他好文 时间:
2014-09-06 01:00:42
阅读次数:
186
题目大概就是考察,如何找到山峰的峰值。从左到右扫一遍,再从右到左扫一遍,确定每个位置的峰值。 1 class Solution { 2 public: 3 int Max(int a,int b) 4 { 5 return a>b?a:b; 6 } 7 ...
分类:
其他好文 时间:
2014-09-06 00:58:22
阅读次数:
352
public class Solution { public void merge(int A[], int m, int B[], int n) { int i=m-1, j=n-1, k=m+n-1; while(i>=0 && j>=0) { ...
分类:
其他好文 时间:
2014-09-05 23:41:02
阅读次数:
181
public class Solution { public List preorderTraversal(TreeNode root) { List result = new ArrayList(); Stack nodeStack = new Stack();...
分类:
其他好文 时间:
2014-09-05 22:17:42
阅读次数:
246
问题描述:反转整数,例子:输入:x = 123, return 321; x = -123, return -321方法:class Solution {public: int reverse(int x) { int newX = 0; int sign = 1;...
分类:
其他好文 时间:
2014-09-05 10:00:51
阅读次数:
174
public class Solution { public List postorderTraversal(TreeNode root) { List result = new ArrayList(); Stack nodeStack = new Stack();...
分类:
其他好文 时间:
2014-09-05 02:08:10
阅读次数:
166