![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
Spade_
故不积跬步,无以至千里;不积小流,无以成江海。持续精进,刻意练习。
展开
-
[牛客网题库] 牛牛的背包问题
牛牛准备参加学校组织的春游, 出发前牛牛准备往背包里装入一些零食, 牛牛的背包容量为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 评论 -
C++ 虚函数与纯虚函数
一、C++虚函数1、什么是虚函数?(虚函数只能借助于指针或者引用来达到多态的效果)class A{public: virtual void foo()// 虚函数关键字 virtual { cout<<"A::foo() is called"<<endl; }};class B:public A{public: void foo...原创 2018-03-06 23:21:34 · 19692 阅读 · 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 评论 -
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 评论 -
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 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 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 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 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 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 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 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 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 评论 -
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 评论 -
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 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 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using extra space?题意:给你一个链...原创 2018-03-17 16:29:30 · 19408 阅读 · 0 评论 -
LeetCode 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?题意:查看一个链表是否存在圈,不使用额外的空间 分析:不使用额外的空间意味着空间复杂度为O(1) 解题思路看代码:/** * Definition for sin...原创 2018-03-17 14:05:12 · 12513 阅读 · 0 评论 -
LeetCode 191. Number of 1 Bits
191. Number of 1 Bits Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11’ has binary re...原创 2018-03-17 00:41:19 · 19273 阅读 · 0 评论 -
LeetCode 72. Edit Distance
72. Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations per...原创 2018-03-17 00:29:31 · 19513 阅读 · 0 评论 -
LeetCode 139. Word Break
139. Word Break Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary wo...原创 2018-03-17 00:22:35 · 19372 阅读 · 0 评论 -
LeetCode 187. Repeated DNA Sequences
187. Repeated DNA Sequences All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated seq...原创 2018-03-17 00:05:44 · 19307 阅读 · 0 评论 -
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 评论