![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法与数据结构
文章平均质量分 95
Spade_
故不积跬步,无以至千里;不积小流,无以成江海。持续精进,刻意练习。
展开
-
[Python] 详解使用动态规划求解最大回撤并绘图
[Python] 使用动态规划求解最大回撤并绘图首先,我们要理解什么是最大回撤。最大回撤:有一个数组,求其中两个数x,y,满足x的索引小于y的索引,使得 x-y 最大。 下面举例几种情况:[1,2,3,4,5,6,7,8,9]: 最大回撤是-1。 (1)[9,8,7,6,5,4,3,2,1]: 最大回撤是8,对应的x=9,y=1。 (2)[3,7,2,6,4,1,9,8,5]: 最大回撤是6,对应的x=7,y=1。 (3)[2,3,5,2,4,1,9,2,6]: 最大回原创 2021-01-07 22:36:05 · 2256 阅读 · 4 评论 -
[牛客网题库] 牛牛的背包问题
牛牛准备参加学校组织的春游, 出发前牛牛准备往背包里装入一些零食, 牛牛的背包容量为w。 牛牛家里一共有n袋零食, 第i袋零食体积为v[i]。 牛牛想知道在总体积不超过背包容量的情况下,他一共有多少种零食放法(总体积为0也算一种放法)。输入描述: 输入包括两行 第一行为两个正整数n和w(1 <= n <= 30, 1 <= w <= 2 * 10^9),表示...原创 2018-03-28 12:07:36 · 540 阅读 · 0 评论 -
[牛客网题库] 被3整除
小Q得到一个神奇的数列: 1, 12, 123,…12345678910,1234567891011…。并且小Q对于能否被3整除这个性质很感兴趣。小Q现在希望你能帮他计算一下从数列的第l个到第r个(包含端点)有多少个数可以被3整除。输入描述: 输入包括两个整数l和r(1 <= l <= r <= 1e9), 表示要求解的区间两端。输出描述: 输出...原创 2018-03-28 12:15:56 · 19571 阅读 · 0 评论 -
LeetCode 152. Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest pr...原创 2018-03-25 17:44:33 · 19390 阅读 · 0 评论 -
LeetCode 200. Number of Islands
Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume...原创 2018-03-25 22:20:53 · 19354 阅读 · 0 评论 -
LeetCode 221. Maximal Square
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0...原创 2018-03-26 21:46:20 · 23019 阅读 · 0 评论 -
LeetCode 287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi...原创 2018-03-27 01:12:54 · 19354 阅读 · 0 评论 -
LeetCode 239. Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window m...原创 2018-03-28 23:16:25 · 19583 阅读 · 0 评论 -
LeetCode 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. 题意:给你一个无序整数数组,找到最长递增子序列的长度。For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subseque...原创 2018-03-29 12:52:58 · 19555 阅读 · 0 评论 -
LeetCode 207.Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a p...原创 2018-03-20 23:50:08 · 19509 阅读 · 0 评论 -
LeetCode 210. Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pa...原创 2018-03-21 12:06:41 · 19284 阅读 · 0 评论 -
LeetCode 234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?题意:给你一个单链表,判断它是否回文 另外:你能否在时间复杂度O(n)、空间复杂度O(1)的情况下完成?/* 利用一快一慢两枚指针二分链表,再将链表前一半...原创 2018-03-18 10:48:25 · 19294 阅读 · 0 评论 -
C++快速排序的实现(注释超详细)
C++快速排序的实现1、QuickSort.h/* 初始版本,升序排序 *//* 时间复杂度:最好O(nlbn),平均O(nlbn),最坏0(n^2) 空间复杂度:O(lbn) 递归栈最大深度为[lbn] + 1 不稳定:情况基于每次划分选择的主元。随机化快排得到理论最坏情况的可能性仅为1/(2^n)/** 快排思想:* 1. 随机选取一个主元作为基准,从待排序记录序列左右两端...原创 2018-03-11 14:00:05 · 21231 阅读 · 1 评论 -
C++堆排序的实现(超详细)
C++堆排序的实现完整代码分享一篇讲解堆排序基本概念的文章,很生动形象:https://mp.weixin.qq.com/s?__biz=MzIwNTc4NTEwOQ==&mid=2247484709&idx=2&sn=7bd9b16069d5a37f9ef521c33f9475641、HeapSort.h/* 初始版本,升序排序 *//* 时间复杂度O(nlbn),空间...原创 2018-03-11 14:03:45 · 25793 阅读 · 3 评论 -
C++ 模拟List
#ifndef MYLIST_H#define MYLIST_H#include<iostream>#include<iomanip>#include<string>#include<string.h>#include<malloc.h>#include<stdlib.h>using namespace s...原创 2018-03-17 16:38:45 · 18634 阅读 · 0 评论 -
LeetCode 148. Sort List
148. Sort List Sort a linked list in O(n log n) time using constant space complexity.题意:使用固定的空间复杂度对一个链表在O(n log n)时间复杂度下排序 解决思路:对于链表,不能使用交换排序,可以使用插入排序中的二路归并排序。 1. 我们可以利用一快一慢指针将链表二分,快指针每次移动2步,慢指针每...原创 2018-03-17 19:43:52 · 19443 阅读 · 0 评论 -
LeetCode 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ ...原创 2018-03-17 21:02:35 · 19471 阅读 · 0 评论 -
LeetCode 206. Reverse Linked List
206. Reverse Linked List Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?题意:逆置一个单链表。 提示:您能否使用迭代和递归两种方法?/* ...原创 2018-03-17 23:29:55 · 13269 阅读 · 0 评论 -
C++归并排序(注释超详细)
C++归并排序的实现1、MergeSort.h/* 初始版本,升序排序 *//* 时间复杂度:O(nlbn) 将n个待排序记录归并次数为lbn,一趟归并O(n) 空间复杂度:O(n) 递归栈最大深度为[lbn] + 1 ,而辅助数组大小为n 稳定:无论最好还是最坏情况时间复杂度都是O(nlbn)*/#ifndef MERGESORT_H#define MERGESORT_H...原创 2018-03-11 13:54:55 · 31628 阅读 · 10 评论