惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
Webroot Blog
Webroot Blog
GbyAI
GbyAI
S
SegmentFault 最新的问题
Cyberwarzone
Cyberwarzone
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 【当耐特】
S
Secure Thoughts
酷 壳 – CoolShell
酷 壳 – CoolShell
AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
S
Security Affairs
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
Spread Privacy
Spread Privacy
T
Threatpost
Forbes - Security
Forbes - Security
C
Cisco Blogs
Scott Helme
Scott Helme
Attack and Defense Labs
Attack and Defense Labs
Simon Willison's Weblog
Simon Willison's Weblog
腾讯CDC
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
Last Week in AI
Last Week in AI
Recorded Future
Recorded Future
小众软件
小众软件
V
Vulnerabilities – Threatpost
美团技术团队
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News - Newest:
Hacker News - Newest: "LLM"
I
Intezer
月光博客
月光博客
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 司徒正美
C
Cybersecurity and Infrastructure Security Agency CISA
Martin Fowler
Martin Fowler
博客园 - 聂微东

Shiroha白羽的博客

Golang 踩坑 —— interface 为参数的时候传 nil 指针 Codeforces Round 925 (Div. 3) Codeforces Round 924 (Div. 2) Codeforces Round 923 (Div. 3) Codeforces Round 922 (Div. 2) Codeforces Round 921 (Div. 2) Educational Codeforces Round 161 (Rated for Div. 2) Codeforces Round 920 (Div. 3) Codeforces Round 919 (Div. 2) Hello 2024 Good Bye 2023 Codeforces Round 918 (Div. 4) 个人备份的常用 macOS 清理命令 Codeforces Round 917 (Div. 2) Pinely Round 3 (Div. 1 + Div. 2) Educational Codeforces Round 160 (Rated for Div. 2) Codeforces Round 915 (Div. 2) Codeforces Round 914 (Div. 2) Codeforces Round 913 (Div. 3) Educational Codeforces Round 159 (Rated for Div. 2) Codeforces Round 912 (Div. 2) Codeforces Round 911 (Div. 2) CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!) Educational Codeforces Round 158 (Rated for Div. 2) Codeforces Round 910 (Div. 2) Codeforces Round 909 (Div. 3) Codeforces Round 908 (Div. 2) Educational Codeforces Round 157 (Rated for Div. 2) C++自定义的字面量 Codeforces Round 907 (Div. 2) Codeforces Round 916 (Div. 3) 关于 LRU map 的一些灵感 2023 杭州站 ICPC 现场赛 反复横跳的 Clang-Tidy(cert-dcl21-cpp) Codeforces Round 906 (Div. 2) 一段奇怪的 CPP 代码 Codeforces Round 905 (Div. 3) Codeforces Round 904 (Div. 2) Codeforces Round 903 (Div. 3) Educational Codeforces Round 156 (Rated for Div. 2) Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round) Codeforces Round 901 (Div. 2) Codeforces Round 900 (Div. 3) Codeforces Round 899 (Div. 2) Educational Codeforces Round#155 (Div. 2) Codeforces Round 898 (Div. 4) CodeTON Round 6 (Div. 2) Codeforces Round 897 (Div. 2) Codeforces Round 896 (Div. 2) Codeforces Round 887 (Div. 2) Codeforces Round 895 (Div. 3) 左值-右值-将亡值 blog.mauve.icu Pinely Round 2 (Div. 1 + Div. 2) Harbour.Space Scholarship Contest 2023-2024 (Div. 1 + Div. 2) Codeforces Round 894 (Div. 3) Codeforces Round 888 (Div. 3) Educational Codeforces Round#153 (Div. 2) Codeforces Round 893 (Div. 2) OTPAUTH,两步验证中的通用协议 Codeforces Round 892 (Div. 2) Codeforces Round 891 (Div. 3) Codeforces Round 890 (Div. 2) Educational Codeforces Round#152 (Div. 2) blog.mauve.icu Java Script 的 null 和 undefined 随想 记一次 SQL LEFT JOIN 没有得到预期结果的错误 Codeforces Round#789(Div. 2) GCC/G++ 预编译头性能优化 使用 Junit5 和 Mockito 实现 SpringBoot 的单元测试最优美的解决方案 centOS 防火墙 docker-compse 的问题 C++ 语言实现动态变化的线程池 Codeforces Round#744 (Div. 3) 计算机图形学 Windows 通过网络访问 WSL2 原生 JavaScript 实现图片裁剪 面试复习(计算机图形学) Codeforces Round#706(Div. 2)-Let's Go Hiking 面试复习(Java) 面试复习(Git) 面试复习(Linux) 面试复习(数据库) 面试复习(计算机网络) 面试复习(操作系统) 面试复习(C++) Codeforces Round#699 (Div. 2) 清理 WSL2 的磁盘占用 Codeforces Round#697 (Div. 3) Windows 下的 NTFS 驱动器索引 BUG 计算机网络复习 记一次 Navicat 连接 MySQL 一直报认证错误(Access denied) 计算机网络实验复习 WSL1 使用 Docker 一直无法启动 我的ACM脚印 2020牛客暑期多校训练营(第三场)D-Points Construction Problem——构造 2020牛客暑期多校训练营(第三场)E-Two Matchings——复杂思维与简单dp 2020牛客暑期多校训练营(第二场)I-Interval——最大流转对偶图求最短路 Educational Codeforces Round 80 D. Minimax Problem——二分+二进制处理 Codeforces Round 606 E. Two Fairs——图论 Codeforces Round 612 (Div. 2) C. Garland——DP
面试复习(算法)
Shiroha · 2021-03-27 · via Shiroha白羽的博客

链表有环问题

  • 判断单向链表是否有环
    • 定义两个指针,从链表的开始,同时沿着链表指针移动,速度分别为一个单位和两个单位。当某个时刻,两个指针指向同一个节点的时候则此链表有环
    • 理论上,速度可以是任意的两个不同的值,因为只要速度差和环的长度有最小公倍数,则必定存在相交的时间点
  • 找出链表的环的交点位置
    • 通过上述步骤(速度取一步两步),当两个指针第一次相遇的时候,将速度为二步的指针移动至开头,并将速度调整为一步,然后两个指针继续前进,直到第一次相遇,此相遇点即为链表的环的交点
    • 原理:把整个链表认为长度就是两步的那个指针所走过的路程,把重复的那部分复制一份,将链表展开为无环。此时可以认为整个链表长度为 $2n$,且一步的那个指针恰好位于整个链表最中间的地方,即 $n$,同时,在展开之前,这两个节点是“相同的节点”,此时如果再有一个指针以一步的速度从开头开始走,那么当这两个指针分别走到链表的正中间和最后的时候,此时这两个指针实际上相同了,而这两个指针速度相同,所以在之前应该也有一段时间已经相同了。反过来,当他们第一次重合的时候,即为环的入口
  • 判断两个链表是否最终交在同一个节点
    • 利用上述的规则,将其中一个链表的头尾相连,然后从另一个链表开头进行一步两步的判断

洗牌问题

  • 问题样式
    • 在 $n$ 个不相同的数中随机取出 $m$ 个数,使得这 $m$ 个数字不同
    • 一个长度为 $n$ 的数组,将其打散
  • 解题方法
    • Fisher-Yates Shuffle算法
      • 优点:逻辑简单
      • 缺点:时间复杂度高($O(n^2)$),空间复杂度也较高($O(n)$),而且需要提前知道数组长度
        1. 设定 $x = n$
        1. 获得一个在 $[1, x]$ 之间的随机数 $t$
        1. 将原数组中第 $t$ 个没有被取出的数据拿出
        1. 使得 $x = x - 1$
        1. 重复 2-4 步直到取出 $m$ 个整数
    • Knuth-Durstenfeld Shuffle算法
      • 优点:时间复杂度($O(n)$)和空间复杂度($O(1)$)都低
      • 缺点:会修改原数组,而且需要提前知道数组长度
        1. 设定 $x = 1$
        1. 获得一个在 $[x, n]$ 之间的随机数 $t$
        1. 交换数组中的第 $x$ 个和第 $t$ 个值
        1. 使得 $x = x + 1$
        1. 重复 2-4 步直到 $x = m + 1$
    • Inside-Out Algorithm算法
      • 优点:时间复杂度($O(n)$)低,不需要提前知道数组长度
      • 缺点:空间复杂度高($O(n)$)
        1. 将整个数据拷贝至一个新的数组 $a$
        1. 设定 $x = 1$
        1. 获取一个在 $[1, x]$ 之间的随机数 $t$
        1. 交换 $a_x$ 和 $a_t$
        1. 使得 $x = x + 1$
        1. 重复 3-5 步直到 $x = m + 1$

快速排序

  • 快速排序的实现
  • 快速排序的优缺点
    • 优点:平均时间复杂度 $O(Nlog_2N)$,空间复杂度 $O(1)$
    • 缺点:不稳定,初始序列有序或基本有序时,时间复杂度降为 $O(n^2)$