码迷,mamicode.com
首页 >  
搜索关键字:solution upgrade    ( 13024个结果)
leetcode 逆转字符串 当年的第一题,今天再写一遍,物是人非
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
LeetCode OJ-- 二战 Combinations
在1 - 10 中,求出 7 个数的排列组合。出现了超时,而超时的原因是有好多重复情况,复杂度上来说,和答案的复杂度是一样的,但是答案中重复了太多了,体会下。超时1:class Solution {public: vector > combine(int n, int k) { ...
分类:其他好文   时间:2014-09-06 22:28:03    阅读次数:363
Generate Parentheses
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 Lists
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
[LeetCode] Generate Parentheses
public class Solution { public List generateParenthesis(int n) { List result = new ArrayList(); Stack numStack = new Stack(); ...
分类:其他好文   时间:2014-09-06 01:00:42    阅读次数:186
Candy
题目大概就是考察,如何找到山峰的峰值。从左到右扫一遍,再从右到左扫一遍,确定每个位置的峰值。 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
[LeetCode] Merge Sorted Array
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
[LeetCode] Binary Tree Preorder Traversal
public class Solution { public List preorderTraversal(TreeNode root) { List result = new ArrayList(); Stack nodeStack = new Stack();...
分类:其他好文   时间:2014-09-05 22:17:42    阅读次数:246
Reverse Integer---反转整数
问题描述:反转整数,例子:输入: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
[LeetCode] Binary Tree Postorder Traversal
public class Solution { public List postorderTraversal(TreeNode root) { List result = new ArrayList(); Stack nodeStack = new Stack();...
分类:其他好文   时间:2014-09-05 02:08:10    阅读次数:166
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!