刷题记录
文章平均质量分 54
都卜冰
这个作者很懒,什么都没留下…
展开
-
【前缀和+Map】Leetcode560寻找等于K的子数组
1.题目Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k.Example 1:Input: nums = [1,1,1], k = 2Output: 2Example 2:Input: nums = [1,2,3], k = 3Output: 2 Constraints:1 <= num原创 2021-09-12 18:53:56 · 117 阅读 · 0 评论 -
【贪心算法】LeetCode1024 视频剪辑
1.题目1024 Video Stitching找出包含至Time的区间You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.Each video clip is described by an array clips where原创 2021-07-22 23:30:24 · 428 阅读 · 1 评论 -
【NJU2018】DP+BFS
1. 201801(南京内高校)A.给出一个多叉树(多于二叉)的先序遍历和后序遍历,(每个节点以字符串标识),求该树的深度。没有数据范围/*将后续遍历逆序,问题等价为最长公共子序列的长度*/#include <iostream>#include <string>using namespace std;const int N = 1000+5;int dp[N][N];string Reverse(string a){ string res="";原创 2021-07-19 22:23:34 · 213 阅读 · 0 评论 -
【CSP 202104-2 csp】邻域均值(DP、二维前缀和)
参考链接1: link.链接2: link.【注意】未debug答案!!!///*4 16 1 60 1 2 34 5 6 78 9 10 1112 13 14 15*/#include <iostream>#include <string>#include<vector>using namespace std;int pic[605][605];int save[605][605];int main(){ ios::sync_..原创 2021-07-19 22:20:45 · 279 阅读 · 0 评论 -
【双指针问题】
1.分析双指针技巧再分为两类,一类是**「快慢指针」,一类是「左右指针」**。前者解决主要解决链表中的问题,比如典型的判定链表中是否包含环;后者主要解决数组(或者字符串)中的问题,比如二分查找。2.快慢指针2.1 判断单向链表是否有环(Leetcode141)两个指针,一个跑得快,一个跑得慢。如果不含有环,跑得快的那个指针最终会遇到null,说明链表不含环;如果含有环,快指针最终会超慢指针一圈,和慢指针相遇,说明链表含有环。class Solution {public: bool ha原创 2021-07-18 23:05:30 · 100 阅读 · 1 评论 -
【最长回文子串和子序列】LeetCode5
1.题目(最长回文子串)Given a string s, return the longest palindromic substring in s.Example 1:Input: s = "babad"Output: "bab"Note: "aba" is also a valid answer.Example 2:Input: s = "cbbd"Output: "bb"Example 3:Input: s = "a"Output: "a"Example 4:Inpu原创 2021-07-17 15:17:09 · 65 阅读 · 0 评论 -
【动态规划DP】最大连续字段和+背包问题
1.Leetcode 53给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。示例:输入: [-2,1,-3,4,-1,2,1,-5,4],输出: 6解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。class Solution {public: int maxSubArray(vector<int>& nums) { //保存以当前字符结尾的最大连续字段和 int原创 2021-07-16 10:55:09 · 163 阅读 · 0 评论 -
【BFS】LeetCode752:开锁的最小次数(Medium)
1.题目在不能出现 deadends情况,计算出最少的转动次数You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’. The wheels can rotate freely and wrap around: for example we can turn ‘9’ to be ‘0’, or ‘0’原创 2021-07-15 23:42:33 · 336 阅读 · 1 评论 -
【BFS&递归】求二叉树最小高度
1.题目:求二叉树最小高度【LeetCode111】:判断一棵二叉树的最小高度:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no children.Example 1:In原创 2021-07-15 21:17:19 · 951 阅读 · 0 评论 -
【回溯法】NJU201802
1.题目Missing numberGiven a positive integer n(n≤40), pick n-1 numbers randomly from 1 to n and concatenate them in random order as a string s, which means there is a missing number between 1 and n. Can you find the missing number?(Notice that in some case原创 2021-07-15 11:10:15 · 59 阅读 · 0 评论 -
【回溯法&动态规划】NJU2018
1. 回溯法基本框架给你输入一个数组 nums 和一个正整数 k,请你判断 nums 是否能够被平分为元素和相同的 k 个子集。// k 个桶(集合),记录每个桶装的数字之和int[] bucket = new int[k];// 穷举 nums 中的每个数字void backtrack(int[] nums, int index) { // base case if (index == nums.length) { return; } // 穷举原创 2021-07-14 18:58:26 · 138 阅读 · 0 评论 -
【常用排序算法整理】
1.归并算法归并排序(排序的方法一种,速度比选择排序、插入排序等快很多)适合较多数据排序举例:int main(){int arr[] = {4, 7, 6, 5, 2, 1, 8, 2, 9, 1};mergeSort(arr, 0, 9);printList(arr, 10);system(“pause”);return 0;}#include<stdio.h>#define ArrLen 20void printList(int arr[], int len) {原创 2021-06-26 00:03:42 · 52 阅读 · 0 评论 -
【Leetcode25】如何K个一组反转链表
1.题目Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, i原创 2021-06-20 22:02:59 · 59 阅读 · 0 评论 -
【Leetcode 92】链表反转
1.递归反转整个链表递归返回后,head的nextt仍指向反转链表末尾,修改末尾指针即可,而反转链表头部则从递归最深层逐渐传递出去。2.反转链表前 N 个节点需记录最后一个反转点的下一个结点,作为头部的接点3. 反转链表的一部分只需逐步向前迭代,到达需反转的起点,即可调用2的反转链表前 N 个节点方法4. 代码链接: link....原创 2021-06-20 11:29:07 · 81 阅读 · 0 评论 -
带备忘录的动态规划【leetcode931】
带备忘录的动态规划【leetcode931】1. C++中vector<vector >的定义vector<vector<int> > A;//正确的定义方式vector<vector<int>> A;//C++11后支持2. C++中vector<vector >的大小//vector<vector<int> >A中的vector元素的个数len = A.size();//vector<v原创 2021-05-27 23:38:25 · 95 阅读 · 0 评论 -
笔试1 vector+排序
vector+排序(60%通过)#include <iostream>#include <map>#include <algorithm>#include<vector>using namespace std;multimap <int, int> keeptimes;int times[1000005];typedef pair<int, int>PAIR;bool cmp_by_value(const PAIR&原创 2021-04-18 22:02:47 · 96 阅读 · 0 评论