题目: 输入一个整型数组,数组里有正数也有负数,数组中一个或连续多个整数组成一个子数组,求所有子数组的和的最大值。要求时间复杂度为O(n) 思路: 1、数组累加 从头到尾逐个累加数组中的每个数字,当累加之和小于0时,从下…
分类:动态规划
(算法)金钗赛诗
题目: 赛诗会后,十二金钗待奔前程。分别宴上,12人各写了一首诗放入包囊。 大家随机取一个,若取到自己的诗,则再取一个,并放回自己的诗,12人都拿到诗算一种分配。 请问:共有多少种不同的分配? 思路: 问题简化:给定n个…
(剑指Offer)面试题9:斐波那契数列
题目: 现在要求输入一个整数n,请你输出斐波那契数列的第n项。 斐波那契数列的定义: f(0)=0;f(1)=1; f(n)=f(n-1)+f(n-2) 思路: 1、递归: 根据递推公式来实现 优点:代码简单,易懂 缺点…
(LeetCode 72)Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word…
(LeetCode 53)Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For e…
(LeetCode 64)Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom r…