摘要: 快慢指针技巧汇总 双指针技巧可以分为两类:一类是【快慢指针】、一类是【左右指针】 一、快慢指针 快慢指针一般初始化指向链表头结点head,前进时快指针fast在前,慢指针slow在后,巧妙解决链表中的一些问题。 1、判断链表中是否有环 经典解法就是用两个指针,一个每次前进两步,一个每次前进一步。如果 阅读全文
posted @ 2021-02-26 00:00 Captand 阅读(361) 评论(0) 推荐(0) 编辑
摘要: 本文只是解决安装ubuntu安装中遇到的一般卡死问题,一些详细的安装过程可以参考其他博客 1.制作启动盘(可以用rufus,非常方便) 2.系统分配空间,ctrl + X, 进入磁盘管理,点击想要磁盘进行压缩卷,大约100G为好。 2.重启电脑,快速按F2进入BIOS界面模式,选择Boot,将Fas 阅读全文
posted @ 2020-07-29 18:52 Captand 阅读(2096) 评论(0) 推荐(0) 编辑
摘要: #include <cstring> #include <iostream> #include <algorithm> #include <queue> using namespace std; const int N = 1001010; int e[N], ne[N], head[N], tot 阅读全文
posted @ 2020-07-20 16:31 Captand 阅读(169) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int main() { long long int a, b, p, sum = 1; scanf("%lld%lld%lld",&a, &b, &p); sum = 1 % p; while(b) { if(b & 阅读全文
posted @ 2020-07-18 22:22 Captand 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。 示例: s = "abaccdeff"返回 "b" s = "" 返回 " " 程序代码 class Solution { public: char firstUniqChar(string s 阅读全文
posted @ 2020-07-18 19:08 Captand 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 1.将数字转化为字符串 方法1: #include<iostream> using namespace std; int main() { int n = 123; cout << to_string(n) << endl; return 0; } 方法2: #include <iostream># 阅读全文
posted @ 2020-07-14 15:00 Captand 阅读(636) 评论(0) 推荐(0) 编辑
摘要: 利用栈和stringstream将带空格的字符串逆序输出 #include <iostream> #include <sstream> #include <stack> using namespace std; int main() { string s; stack<string> q; stri 阅读全文
posted @ 2020-07-14 14:55 Captand 阅读(488) 评论(0) 推荐(0) 编辑
摘要: 题目描述: 给你一个整数数组 nums 。 如果一组数字 (i,j) 满足 nums[i] == nums[j] 且 i < j ,就可以认为这是一组 好数对 。 返回好数对的数目。 示例1: 输入:nums = [1,2,3,1,1,3]输出:4解释:有 4 组好数对,分别是 (0,3), (0, 阅读全文
posted @ 2020-07-14 13:50 Captand 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 题目描述:给定两个数组,编写函数来计算它们的交集。 示例1:输入:nums1 = [1,2,2,1], nums2 = [2,2] 输出:[2,2]示例2:输入:nums1 = [4,9,5], nums2 = [9,4,9,8,4]输出:[4,9]1.排序方法: class Solution { 阅读全文
posted @ 2020-07-13 20:20 Captand 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 埃氏筛理解与代码模板 #include <iostream> #include <cstring> using namespace std; const int N = 10010; bool isprime[N]; int n, prime[N], tot; int Era_prime(int n 阅读全文
posted @ 2020-07-13 15:58 Captand 阅读(151) 评论(0) 推荐(0) 编辑