码迷,mamicode.com
首页 >  
搜索关键字:maximum recursion    ( 4597个结果
Best Time to Buy and Sell Stock II
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a...
分类:其他好文   时间:2014-07-09 23:32:44    阅读次数:276
翻转整数 Reverse digits of a number
两种方法翻转一个整数,顺序翻转和递归翻转这里没考虑overflow的情况递归的作用是使得反向处理,即从递归栈的最低端开始处理,通过画图可得。如果是rec(num/10):123451234123121         package recursion; public class Reverse_digits_of_a_number { public static void main(Str...
分类:其他好文   时间:2014-07-08 18:34:14    阅读次数:208
判断一个整数是否为回文数 Check if a number is palindrome
一种方法是先翻转当前数,然后把它和原数比较(略)另一种是递归方法,借用一个复制数,对原数递归,使之翻转,然后配合复制数比较package recursion; public class Check_if_a_number_is_palindrome { public static void main(String[] args) { int num = 121321; System....
分类:其他好文   时间:2014-07-08 17:13:55    阅读次数:188
用递归翻转一个栈 Reverse a stack using recursion
明确递归语句之前的语句都是顺序执行,而递归语句之后的语句都是逆序执行package recursion; import java.util.Stack; public class Reverse_a_stack_using_recursion { /* Input stack: 3 2 1 Output stack: 1 2 3 */ public s...
分类:其他好文   时间:2014-07-08 13:39:49    阅读次数:143
[leetcode] Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
分类:其他好文   时间:2014-07-08 00:41:49    阅读次数:235
[Leetcode][Tree][Binary Tree Maximum Path Sum]
找书中权值和最大的路径,至少包含一个点。有点类似LCA(最近公共祖先),树的问题关键是如何划分子问题,然后递归求解。想到了可以返回两种结果,一个是单独路径的最大和,一种是子树的最大和,然后在求解的过程中不断的更新答案。 1 /** 2 * Definition for binary tree 3 ....
分类:其他好文   时间:2014-07-06 14:16:47    阅读次数:187
给出一个set的字符和一个正数k,求所有由这个set能组成长度为k的字符串集合 print-all-combinations-of-given-length
// 给出一个set的字符和一个正数k,求所有由这个set能组成长度为k的字符串集合 /* Input:  set[] = {'a', 'b'}, k = 3 Output: aaa aab aba abb baa bab bba bbb Input:  set[] = {'a', 'b', 'c', 'd'}, k = 1 Output: a b c dpackage recursion...
分类:其他好文   时间:2014-07-06 11:17:20    阅读次数:174
打印出大小为n的数组(可能有重复元素)里所有可能的组合
Input: {1, 2, 3, 4}, r=2 Output: {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4} and {3, 4}.package recursion; import java.util.ArrayList; import java.util.Collections; public class Print_all_possible_com...
分类:其他好文   时间:2014-07-06 11:09:05    阅读次数:183
LeetCode——Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 给定一个字符串S,找出其中的最长回文...
分类:其他好文   时间:2014-07-06 00:15:15    阅读次数:240
POJ 3693 Maximum repetition substring (后缀数组)
题目大意: 求出字典序最小,重复次数最多,的子串。 思路分析: RMQ + height 数组可以求出任意两个后缀的lcp 我们枚举答案字符串的重复的长度。 如果这个字符串的长度为 l ,而且这个字符串出现过两次或两次以上 那么你会发现在原串中  str[0] str[l] str[2*l] ....肯定有相邻的两个被包含在重复的串中。 我们求出这两个相邻的后缀的lcp 我...
分类:其他好文   时间:2014-07-05 23:47:48    阅读次数:178
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!