www.flydean.com
  • README
  • blog
    • 新版博客回归啦
    • projects
      • 一键自动化博客发布工具,用过的人都说好(简书篇)
      • 一键自动化博客发布工具,chrome和firfox详细配置
      • 一键自动化博客发布工具,用过的人都说好(segmentfault篇)
      • 一键自动化博客发布工具,用过的人都说好(oschina篇)
      • 一键自动化博客发布工具,用过的人都说好(阿里云篇)
      • 一键自动化博客发布工具,用过的人都说好(cnblogs篇)
      • 一键自动化博客发布工具,用过的人都说好(infoq篇)
      • 一键自动化博客发布工具,用过的人都说好(csdn篇)
      • 一键自动化博客发布工具,用过的人都说好(51cto篇)
      • 一键自动化博客发布工具,用过的人都说好(掘金篇)
      • 一键自动化博客发布工具,用过的人都说好(腾讯云篇)
      • 一键自动化博客发布工具,用过的人都说好(头条篇)
      • 一键自动化博客发布工具,用过的人都说好(知乎篇)
      • 一键自动化博客发布工具,用过的人都说好(公众号篇)
      • moneyPrinterPlus
        • MoneyPrinterPlus:AI自动短视频生成工具,赚钱从来没有这么容易过
        • MoneyPrinterPlus:AI自动短视频生成工具,详细使用教程
        • MoneyPrinterPlus:AI自动短视频生成工具-阿里云配置详解
        • MoneyPrinterPlus:AI自动短视频生成工具-腾讯云配置详解
        • MoneyPrinterPlus:AI自动短视频生成工具-微软云配置详解
        • 重磅!免费一键批量混剪工具它来了,一天上万短视频不是梦
        • 福利来了!MoneyPrinterPlus可以自动配置环境和自动运行了
        • 重磅来袭!MoneyPrinterPlus一键发布短视频到视频号,抖音,快手,小红书上线了
        • MoneyPrinterPlus全面支持本地Ollama大模型
        • 在MoneyPrinterPlus中使用本地chatTTS语音模型
        • fasterWhisper和MoneyPrinterPlus无缝集成
        • 再升级!MoneyPrinterPlus集成GPT_SoVITS
    • tools
      • 来了,永久免费的图床服务
      • 给picgo上传的图片加个水印
      • 手动给docusaurus添加一个搜索
  • docs
    • blockchain
      • 00-blockchain
      • 01-bitcoin
        • 01-bitcoin-overview
        • 02-bitcoin-blockchain-network
        • 03-bitcoin-consensus
        • 04-bitcoin-transactions
        • 05-bitcoin-mine-consensus
        • 06-bitcoin-in-trouble
      • 03-hyperledger
        • 01-Introduction-to-distributed-ledgers
        • 02-hyperledger-fabric-basics
        • 03-technical-advantages-fabric
        • 04-blockchain-vscode-extension
        • 05-use-vs-connect-ibc
        • 06-run-Fabric-on-ibm-Cloud
      • 04-libra
        • 01-libra-white-paper-interpretation
        • 2. Libra教程之:数据结构和存储
        • 3. Libra教程之:执行Transactions
        • 4. Libra教程之:move语言的特点和例子
        • 5. Libra教程之:Libra协议的关键概念
        • 6. Libra protocol的逻辑数据模型
        • 7. Transaction的生命周期
        • 8. 来了,你最爱的Move语言
        • 9. 运行自定义move modules
        • 10. Libra testnet使用指南
      • 02-ethereum
        • Solidity
          • 1. Solidity的Bytecode和Opcode简介
    • cryptology
      • 01-consistency-hash
      • 02-sybil-attack
      • 03-tor
      • 04-hmac
      • 05-erc20-short-address-attack
      • 06-mac-attack
      • 07-one-time-password
      • 8. DES
      • 9. AES
      • 10. 分组密码与模式
      • 11. 私钥公钥系统
      • 12-RSA算法
      • 13. 什么是中间人攻击
      • 14-混合密码系统
      • 15-单向散列函数
      • 16. 数字签名
      • 17. 一文读懂密码学中的证书
      • 18. 密钥详解
      • 19. 更加安全的密钥生成方法Diffie-Hellman
      • 20. 基于口令的密码(PBE)
      • 21. 一篇文章让你彻底弄懂SSL/TLS协议
      • 22-known-plaintext-attack
      • 23-Content-sniffing
      • 24-csrf
      • 25-SHA1-2-3
      • 26-IDEA
      • 27-memory-hard
      • 27-memory-hard_zhihu
      • 28-safer
      • 29-collision-attack
      • 30-birthday-attack
      • 30 Side Channel Attack
      • 31-feistel-cipher
      • 32-blowfish
      • 33-twofish
      • 34 Memory Bound
      • 35-MD-length-extension
      • 36 Sponge Function
      • 37 Bcrypt
      • 38-Argon2
      • 39-Pbkdf2
      • 40-scrypt
      • 41-CORS
      • 42-pki-x509
      • 43-pki-ocsp
      • 44-openssl-ocsp
      • 45-openssl-private-ca
      • 46-ASN.1
      • 47-x690-ber-cer-der
      • 48-PEM-PKCS7812
    • db
      • 01-IndexedDB-kickoff
    • java
      • java程序员从小工到专家成神之路(2024版)
      • 1-java-base
        • 前言
        • 01-string-all-in-one
        • 02-java-string-encodings
        • 03-base-shallow-copy-deep-copy
        • 04-do-you-know-class-name
        • 05-duration-period-ChronoUnit
        • 06-inner-class-inner-interface
        • 07-java-serialization
        • 8. 什么?注释里面的代码居然能够执行
        • 9. Java函数式编程和Lambda表达式
        • 10-lambda-closure
        • 11-type-inference-lambda
        • 12-marker-interface-annotation-processor
        • 13-java-jar-in-detail
        • 14-java-spi-for-extensible-app
        • 15-wordcount-in-one-line
        • 16-how-to-stop-thread
        • 17-why-use-peek
        • 18-checked-exception-in-lambda
      • 2-io-nio
        • 简介
        • 01-io-nio-overview
        • 02-io-file
        • 03-io-try-with
        • 4. 小师妹学JavaIO之:文件读取那些事
        • 5. 小师妹学JavaIO之:文件写入那些事
        • 6. 小师妹学JavaIO之:目录还是文件
        • 7. 小师妹学JavaIO之:文件系统和WatchService
        • 8. 小师妹学JavaIO之:文件File和路径Path
        • 9. 小师妹学JavaIO之:Buffer和Buff
        • 10. 小师妹学JavaIO之:File copy和File filter
        • 11. 小师妹学JavaIO之:NIO中Channel的妙用
        • 12. 小师妹学JavaIO之:MappedByteBuffer多大的文件我都装得下
        • 13. 小师妹学JavaIO之:NIO中那些奇怪的Buffer
        • 14. 小师妹学JavaIO之:用Selector来说再见
        • 15. 小师妹学JavaIO之:文件编码和字符集Unicode
      • 3-concurrent
        • 简介
        • 1. java.util.concurrent简介
        • 2. java并发中的Synchronized关键词
        • 3. java中的Volatile关键字使用
        • 4. java中wait和sleep的区别
        • 5. java中Future的使用
        • 6. java并发中ExecutorService的使用
        • 7. java中Runnable和Callable的区别
        • 8. java中ThreadLocal的使用
        • 9. java中线程的生命周期
        • 10. java中join的使用
        • 11. 怎么在java中关闭一个thread
        • 12. java中的Atomic类
        • 13. java中interrupt,interrupted和isInterrupted的区别
        • 14. java中的daemon thread
        • 15. java中ThreadPool的介绍和使用
        • 16. java 中的fork join框架
        • 17. java并发中CountDownLatch的使用
        • 18. java中CyclicBarrier的使用
        • 19. 在java中使用JMH(Java Microbenchmark Harness)做性能测试
        • 20. java中ThreadLocalRandom的使用
        • 21. java中FutureTask的使用
        • 22. java中CompletableFuture的使用
        • 23. java中使用Semaphore构建阻塞对象池
        • 24. 在java中构建高效的结果缓存
        • 25. java中CompletionService的使用
        • 26. 使用ExecutorService来停止线程服务
        • 27. 我们的线程被饿死了
        • 28. java中有界队列的饱和策略(reject policy)
        • 29. 由于不当的执行顺序导致的死锁
        • 30. 非阻塞同步机制和CAS
        • 31. 非阻塞算法(Lock-Free)的实现
        • 32. java内存模型(JMM)和happens-before
        • 33. java多线程之Phaser
        • 34. java中Locks的使用
        • 35. ABA问题的本质及其解决办法
        • 36. 并发和Read-copy update(RCU)
        • 37. 同步类的基础AbstractQueuedSynchronizer(AQS)
        • 38. java并发Exchanger的使用
      • 4-stream
        • 简介
        • 00001-java-8-streams-Introduction
        • 00002-functional-interface
        • 00003-lambda-best-practices
        • 00004-java-8-stream-ifelse
        • 00005-java-8-stream-map
        • 00006-java-rethrow
        • 00007-java-Collectors
        • 00008-java-8-stream-reduce
        • 00009-java-8-Spliterator
        • 00010-java-8-stream-foreach-break
        • 00011-java-8-predicate-chain
        • 00012-java-8-infinite-stream
        • 00013-java-8-stream-cust-pool
        • 00014-java-8-stream-peek
        • 00015-java-custom-collector
        • 00016-java-8-lambda-exception
      • 5-collections
        • 前言
        • 01-asList-arraylist
        • 02-Comparable-Comparator
        • 03-enumMap-enumSet
        • 04-Generics-in-deep
        • 05-hashMap-LinkedHashMap
        • 06-HashMap-TreeMap
        • 07-how-to-copy-list
        • 08-iterator-to-list
        • 09-java-fail-safe-fail-fast
        • 10-queue-overview
        • 11-PriorityQueue
        • 12-SynchronousQueue
        • 13-type-erase
        • 14-reference-referenceType
        • 15-skiplist-ConcurrentSkipListMap
        • 16-DelayQueue
      • 6-jvm
        • 00-java-jvm-all-in-one
        • 1. 小师妹学JVM之:JVM的架构和执行过程
        • 2. 终于我用JOL打破了你对java对象的所有想象
        • 3. 小师妹学JVM之:java的字节码byte code简介
        • 4. 小师妹学JVM之:Dirty cards和PLAB
        • 5. 小师妹学JVM之:JVM中栈的frames详解
        • 6. 如果你想写自己的Benchmark框架
        • 7. JVM详解之:java class文件的密码本
        • 8. JVM系列之:String,数组和集合类的内存占用大小
        • 9. JVM系列之:Contend注解和false-sharing
        • 10. JVM系列之:对象的锁状态和同步
        • 11. JVM系列之:String.intern和stringTable
        • 12. JVM系列之:String.intern的性能
        • 13. JVM详解之:本地变量的生命周期
        • 14. JVM详解之:HotSpot VM中的Intrinsic methods
        • 15. JVM系列之:通过一个例子分析JIT的汇编代码
        • 16. JVM详解之:类的加载链接和初始化
        • 17. 小师妹学JVM之:逃逸分析和TLAB
        • 18. JVM系列之:JIT中的Virtual Call
        • 19. JVM系列之:JIT中的Virtual Call接口
        • 20. JVM详解之:运行时常量池
        • 21. 小师妹学JVM之:JDK14中JVM的性能优化
        • 22. JVM系列之:从汇编角度分析Volatile
        • 23. JVM系列之:从汇编角度分析NullCheck
        • 24. 小师妹学JVM之:GC的垃圾回收算法
        • 25. 小师妹学JVM之:JVM中的Safepoints
        • 26. JVM系列之:再谈java中的safepoint
        • 27. troubleshoot之:用control+break解决线程死锁问题
        • 28. troubleshoot之:使用JFR解决内存泄露
        • 29. troubleshoot之:分析OutOfMemoryError异常
        • 30. troubleshoot之:使用JFR分析性能问题
        • 31. troubleshoot之:GC调优到底是什么
        • 32. JVM系列之:详解java object对象在heap中的结构
        • 33. 小师妹学JVM之:深入理解JIT和编译优化-你看不懂系列
        • 34. 小师妹学JVM之:JIT中的LogCompilation
        • 35. 小师妹学JVM之:JIT中的PrintCompilation
        • 36. 小师妹学JVM之:JIT中的PrintAssembly
        • 37. 小师妹学JVM之:JIT中的PrintAssembly续集
        • 38. 小师妹学JVM之:深入理解编译优化之循环展开和粗化锁
        • 39. 小师妹学JVM之:JIT的Profile神器JITWatch
        • 40. 小师妹学JVM之:cache line对代码性能的影响
      • 7-security
        • 00001-java-security-code-line-DOS
        • 00002-java-security-code-line-base
        • 00003-java-security-code-line-object
        • 00004-java-security-code-line-DLC
        • 00005-java-security-code-line-expresion
        • 00006-java-security-code-line-number
        • 00007-java-security-code-line-string
        • 00008-java-security-code-line-heap-pollution
        • 00009-java-security-code-line-object-copy
        • 00010-java-security-code-line-injection
        • 00011-java-security-code-line-input
        • 00012-java-security-code-line-mutability
        • 00013-java-security-code-line-method
        • 00014-java-security-code-line-exception
        • 00015-java-security-code-line-visibility-atomicity
        • 00016-java-security-code-line-lock
        • 00017-java-security-code-line-dead-lock
        • 00018-java-security-code-line-double-check-lock
        • 00019-java-security-code-line-thread
        • 00020-java-security-code-line-threadsafe
        • 00021-java-security-code-line-file-io
        • 00022-java-security-code-line-file-security
        • 00023-java-security-code-line-serialization
        • 00024-java-security-code-line-threadpool
      • 8-new-feature
        • 00-java-new-feature-all-in-one
        • 1. JDK11的重要新特性
        • 2. JDK12的五大重要新特性
        • 3. JDK13的六大重要新特性
        • 04-JDK9-java-module
        • 05-JDK9-String-Compact
        • 06-JDK9-jvm-xlog
        • 07-JDK10-var-usage
        • 08-JDK10-var-genericity-multiple-implements
        • 09-JDK10-var-anonymous-class
        • 10-JDK11-http-reactive
        • 11-JDK11-http-new
        • 12-JDK12-collectors-teeing
        • 13-JDK12-CompactNumberFormat
        • 14-JDK13-appCDS
        • 15. 一览为快,JDK14的新特性
        • 16. JDK 14的新特性:更加好用的NullPointerExceptions
        • 17-JDK14-records
        • 18-JDK14-text-block
        • 19-JDK14-switch
        • 20-JDK14-java-tools
        • 21-JDK14-jcmd
        • 22. JDK14的新特性:instanceof模式匹配
        • 23-JDK14-jfr-jmc-event-stream
        • 24-JDK15-new-features
        • 25-JDK15-release-new-features
        • 26-JDK16-new-features
        • 27-JDK17-new-features
      • 9-advanced-feature
        • 01-Java-Thread-Affinity
        • jna
          • 01-jni-overview
          • 02-jna-overview
          • 03-jna-Library-Mapping
          • 04-jna-type-mapping
          • 05-jna-type-mapping-details
          • 06-jna-memory
          • 07-jna-function
          • 08-jna-structure
          • 09-jna-callbacks
      • netty
        • 01 Netty Startup
        • 02 Netty Bytebuf
        • 03 Netty Architecture
        • 03-netty-bootstrap-ServerBootstrap
        • 04 Netty Channel
        • 04-netty-ChannelHandlerContext
        • 04-netty-ChannelPipeline
        • 04-netty-channel-group
        • 04-netty-channel-types
        • 04-netty-channel-vs-serverChannel
        • 04-netty-socketaddress
        • 05 Netty Channel Event
        • 05-netty-EventExecutor-EventExecutorGroup
        • 05-netty-eventloop-eventloopgroup
        • 05-netty-nioeventloop
        • 06 Netty Cheerup China
        • 07 Netty Stream Based Transport
        • 08 Netty Pojo Buf
        • 09 Netty Reconnect
        • 10 Netty Chat
        • 11 Netty Udp
        • 12 Netty Securechat
        • 13 Netty Customprotocol
        • 14-java-base64
        • 14-netty-ReplayingDecoder
        • 14-netty-codec-base64
        • 14-netty-codec-bytes
        • 14-netty-codec-json
        • 14-netty-codec-msg-to-bytebuf
        • 14-netty-codec-msg-to-msg
        • 14-netty-codec-object
        • 14-netty-codec-string
        • 14-netty-codec-xml
        • 14 Netty Cust Codec
        • 14-netty-frame-decoder
        • 15 Netty Buildin Frame Detection
        • 16 Netty Buildin Codec Common
        • 17-jboss-marshalling
        • 17-netty-marshalling
        • 17-netty-protobuf-UDP
        • 17 Netty Protobuf
        • 18 Netty Http Request
        • 19 Netty Http Client Request
        • 20 Netty Fileserver
        • 21 Netty Http Fileupload
        • 22 Netty Cors
        • 23 Netty Websocket Server
        • 24 Netty Websocket Server 2
        • 25 Netty Websocket Client
        • 26 Netty Secure Http 2
        • 27 Netty Http 2
        • 28 Netty Wrap Http 2
        • 29 Netty Flowcontrol
        • 30 Netty Http 2 Client
        • 31 Netty Framecodec Http 2
        • 32 Netty Http 2 Client Framecodec
        • 33 Netty Multiplex Http 2 Server
        • 34 Netty Multiple Server
        • 35 Netty Simple Proxy
        • 36 Netty Socks Support
        • 37 Netty Cust Socks Server
        • 38-netty-cust-port-unification
        • 39-netty-SelectorProvider-channelFactory
        • 40-netty-udt-support
        • 41-netty-udt-byte-message
        • 42-netty-rendezvous
        • 43-netty-reference-cound
        • 44-netty-tcp-fast-open
        • 45-netty-ByteBuf-ByteBuffer
        • 46-netty-future-executor
        • 47-netty-Thread-local-object-pool
        • 48-netty-fastThreadLocal
        • 49-netty-extensible-enum
        • 50-netty-Hashed-wheel-timer
        • 51-netty-Thread-Affinity
        • 52-netty-native-transport
        • 53-1-netty-kqueue-transport
        • 53-2-netty-epoll-transport
        • 54-netty-dns-over-tcp
        • 55-netty-dns-over-udp
        • 56-netty-dns-over-tls
        • 57-netty-dns-tcpserver
        • 58-netty-haproxy
      • 10-ORM
        • mybatis
          • 01-difference-between-#-and-$
    • reactive
      • reactive system初探
      • 02-reactive-stream
      • r2dbc
        • 01-r2dbc-introduce
        • 02-r2dbc-h2-in-depth
        • 03-r2dbc-mysql-in-depth
        • 04-spring-data-r2dbc
      • reactor
        • 01-introduction-to-reactor
        • 02-reactor-core-in-depth
        • 03-reactor-handle-errors
        • 04-reactor-thread-schedulers
    • scala
      • 00001 Scala Oo
      • 00002 Scala Base
      • 00003 Scala Functional
      • 00004 Scala Statically Typed
      • 5. 可扩展的scala
      • 00006 Scala Parameter
      • 00007 Scala Option Some Null
      • 00008 Scala Enumerations
      • 00009 Scala Partial Function
      • 00010 Scala Futures Promise
      • 00011 Scala Mutable Immutable Collection
      • 00012 Scala Either
      • 00013 Scala Covariance Contravariant
      • 00014 Scala Visibility
      • 00015 Scala Self Type
      • 00016 Scala Existential Type
      • 00017 Scala Higher Kinded
    • web-tech
      • 01-storage-api-limit
      • 02-web-storage-api
      • 03-webworker-kickoff
    • AI
      • 02-math
        • 01-singular-value
        • 02-probability-god-mod
        • 03-Turing-machine
        • 04-p-np-npc-problem
      • 03-machine-learning
        • 01-machine-learning-overview
      • 01-llma
        • langchain
          • 001-langchain-overview
          • 002-langchain-Prompts
          • 003-langchain-custprompts
          • 004-langchain-cust-example-selector
          • 005-langchain-llm
          • 006-langchain-chatmod
          • 007-langchain-output-parthcer
          • 008-langchain-retrieval-overview
          • 009-langchain-retrieval-document-loaders
    • AIGC
      • stable-diffusion
        • Stable diffusion 初学者指南
        • 构建一个优秀的Prompt
        • 轻松复现一张AI图片
        • Stable Diffusion中的常用术语解析
        • Stable diffusion中这些重要的参数你一定要会用
        • Stable Diffusion中的embedding
        • Stable diffusion中的models
        • Stable Diffusion WebUI详细使用指南
        • Stable diffusion采样器详解
        • 原来Stable Diffusion是这样工作的
        • hypernetwork在SD中是怎么工作的
        • SD中的VAE,你不能不懂
        • 手把手教你生成一幅好看的AI图片
        • 什么?这动物图片可以上国家地理?
        • After Detailer让图像自动修复
        • AI图像放大工具,图片放大无所不能
        • LoRA大模型微调的利器
    • Architecture
      • REST
        • 01 REST RES Tful
        • 02 REST Resource
        • 03 REST HATEOAS
      • auth
        • 01-SAML-startup
        • 02-openid-connect-startup
        • 03-OAuth-2.0-in-depth
        • 04-SAML-vs-OAuth2
        • 05-openid-connnect-with-onelogin
        • 06-keycloak-startup
        • 07-keycloak-saml-wildfly
        • 08-keycloak-with-other-system
        • 09-openid-Implicit-onelogin
      • common
        • 01-reactive-system
        • 02-reactive-stream
        • 03-authorization-service
        • 04-keycloak-cluster-in-depth
        • 05-concurrency-parallelism
        • 06-software-architecture
        • 07-data-flow-architecture
        • 09 Microservices Guide
        • 10 Microservices Monolith
        • 11 Serverless Architecture
      • distribution
        • 01 Basic Paxos
        • 02 Generalized Byzantine Paxos
        • 03 Cheap Paxos Fast Paxos
        • 04 Multi Paxos
        • 05 Raft
    • algorithm
      • 01-anime
        • 01-algorithm-bubble-sort
        • 02-algorithm-insertion-sort
        • 03-algorithm-selection-sort
        • 04-algorithm-merge-sort
        • 05-algorithm-quick-sort
        • 06-algorithm-count-sort
        • 07-algorithm-radix-sort
        • 08-algorithm-linked-list
        • 09-algorithm-doubly-linked-list
        • 10-algorithm-stack
        • 11-algorithm-AVL-tree
        • 12-algorithm-queue
        • 13-algorithm-dequeue
        • 14-algorithm-hashtable
        • 15-algorithm-binary-search-tree
        • algorithm-binary-heap
        • algorithm-cyclefinding
        • algorithm-fenwicktree
        • algorithm-recursion
        • algorithm-segmenttree
        • algorithm-suffix-array
        • algorithm-suffix-tree
        • algorithm-ternary-search-tree
        • algorithm-tire
    • cheatSheet
      • cheatsheet
        • 01-jdk8-GC-cheatsheet
        • 02-JDK9-GC-cheatsheet
        • 03-JDK10-GC-cheatsheet
        • 04-JDK11-GC-cheatsheet
        • 05-JDK12-13-14-GC-cheatsheet
      • mindmap
        • Architect
        • Bigdata
        • 区块链技术大合集
        • Golang
        • Java
        • Js
        • Patten
      • tips
        • 01 Db Primary Foregin Keys
        • 01-googleCloud-azure-aws
        • 02 Db Result Set Meta Data
        • 02 New Gitbook To Pdf
        • 03-semantic-version
        • 03 Swagger To Html Pdf
        • 04 Unicode Sorting
        • 05 Git Personal Access Token
        • 06-jetbrains-fleet
        • 07-git-largefile
        • 08-beidou-how-to-work
    • flutter
      • dart
        • 01-dart-variables
        • 02-dart-buildin-type
        • 03-dart-function
        • 04-dart-operator
        • 05-dart-exception
        • 06-dart-class
        • 07-dart-extend
        • 08-dart-Generics
        • 09-dart-packages
        • 10-dart-pubspec
        • 11-dart-create-package
        • 12-dart-async
        • 13-dart-generators
        • 14-dart-number-string
        • 15-dart-collection
        • 16-dart-url
        • 17-dart-date-time
        • 18-dart-math
        • 19-dart-decode-encode
        • 20-dart-html
        • 21-dart-http
        • 22-dart-websockets
        • 23-dart-file
        • 24-dart-null-safety
        • 25-dart-Isolates
        • 26-dart-extension-method
        • 27-dart-style
        • 28-dart-Libraries-effective
        • 29-dart-null-effective
        • 30-dart-collection
      • flutter
        • 01-flutter-architectural
        • 02-flutter-widget
        • 03-flutter-state
        • 04-flutter-BuildContext
        • 05-01-flutter-gestures-demo
        • 05-flutter-gestures
        • 06-flutter-Material-materialApp
        • 07-flutter-ui-layout-overview
        • 08-flutter-ui-layout-container
        • 09-flutter-ui-layout-gridview
        • 10-01-flutter-ui-layout-listview-more
        • 10-flutter-ui-layout-listview
        • 11-flutter-ui-layout-stack
        • 12-flutter-ui-layout-card
        • 13-flutter-ui-constraints
        • 14-flutter-ui-AspectRatio-FractionallySizedBox
        • 15-flutter-ui-boxes
        • 16-flutter-ui-builder
        • 17-flutter-ui-indexed-stack
        • 18-flutter-ui-wrap
        • 19-flutter-ui-offstage
        • 20-flutter-ui-flow
        • 21-flutter-ui-Transform
        • 22-flutter-ui-SliverAppBar
        • 23-flutter-ui-SliverList-SliverGrid
        • 24-flutter-ui-navigation-1
        • 25-flutter-ui-navigation-2
        • 26-flutter-ui-custom-themes
        • 26-flutter-ui-navigation-3
        • 27-flutter-ui-play-video
        • 28-flutter-ui-use-camera
        • 29-flutter-ui-animate-router
        • 30-flutter-ui-animate-resize
        • 31-flutter-ui-animate-controller
        • 32-flutter-ui-animate-download-button
        • 33-flutter-ui-animate-menu
        • 40-flutter-ui-effect-photo-filter
        • 50-flutter-MediaQuery
    • interview
      • architecture
        • 分布式系统
        • 设计模式
      • arithmetic
        • 数组字符串
        • 双指针
        • 滑动窗口
        • 矩阵
        • Hash表格
        • 区间
        • 栈
        • 链表
        • 二叉树
        • 图
        • 字典树
        • 回溯
        • 分治
        • Kadane算法
        • 二分查找
        • 堆
        • 位运算
        • 数学
        • 020-arithmetic-dynamic-planning
        • more
          • 001-arithmetic-01
          • 002-arithmetic-02
          • 算法基础面试题(三)
      • prepare
        • 经典IQ测试题
      • db
        • mysql
          • 001-mysql-01
          • 002-mysql-02
        • redis
          • 001-redis-01
      • java
        • base
          • java基础面试问题(一)
          • 面向对象
          • java基础面试问题(三)
          • Java异常面试题
          • more
            • 001-java-exception
        • collections
          • java集合面试问题(一)
          • java集合面试问题(二)
          • java集合面试问题(三)
          • java集合高级面试问题(一)
          • more
            • 深入理解java List
            • 深入理解java Map
        • concurrent
          • java并发和多线程面试题(一)
          • java并发和多线程面试题(二)
          • java并发和多线程面试题(三)
          • java并发高级面试题(一)
          • java并发高级面试题(二)
          • java并发高级面试题(三)
          • more
            • 007-java-do-you-know-lock
        • io
          • IO面试问题(一)
          • IO面试问题(二)
          • more
            • 高效IO 与 NIO
            • 高级IO应用
        • jvm
          • 001-java-jvm-01
          • 002-java-jvm-02
          • more
            • class字节码和类加载机制
            • 内存泄露
    • javascript
      • ecmascript
        • ecmascript-10
        • ecmascript-11
        • ecmascript-12
        • ecmascript-6
        • ecmascript-7
        • ecmascript-8
        • ecmascript-9
        • es6-Iterables-Iterator
        • es6-promise-generator
        • es8-shared-memory
        • es9-async-iteration
        • es9-regexp
        • js-built-in-objects-structures
        • js-closure
        • js-memory-management
        • js-modules
        • js-use-strict
        • object-oriented-js
      • koa
        • koa-startup
      • nodejs
        • 00001-nodejs-kickoff
        • 00002-nodejs-npm
        • 00003-nodejs-async
        • 00004-nodejs-http-express
        • 00005-nodejs-file-system
        • 00006-nodejs-profile
        • 00007-nodejs-docker-best-practices
        • 00008-nodejs-event
        • 00009-nodejs-event-more
        • 00010-nodejs-block-eventloop
        • 00011-nodejs-http-in-depth
        • 00012-nodejs-worker-thread
        • 00013-nodejs-childprocess
        • 00014-nodejs-cluster
        • 00015-nodejs-debug
    • python
      • 01-python-base
        • 01-python3-cheatsheet
        • 02-python-ipython
        • 03-python-number-list-string
        • 04-python-condition-control
        • 05-python-function
        • 06-python-data-structure
        • 07-python-module
        • 08-python-io
        • 09-python-error-exception
        • 10-python-class
        • 11-python-inner-obj
        • 12-Jupyter-Notebook
        • 13-python-struct-format-char
      • 02-numpy
        • 01-python-numpy-basic
        • 02-python-numpy-datatype
        • 03-python-numpy-scalar
        • 04-python-numpy-datatype-obj
        • 05-python-Structured-arrays
        • 06-python-numpy-genfromtxt
        • 07-python-numpy-broadcasting
        • 08-python-numpy-linear-algebra
        • 09-python-numpy-ndarray
        • 10-python-numpy-func
      • 03-pandas
        • 01-python-pandas-overview
        • 02-python-pandas-advanced
        • 03-python-pandas-data-structures
        • 04-python-pandas-merge
        • 05-python-pandas-reshaping-pivot
        • 06-python-pandas-text
        • 07-python-pandas-missingdata
        • 08-python-pandas-category
        • 09-python-pandas-plot
        • 10-python-pandas-statistical
        • 11-python-pandas-groupby
        • 12-python-pandas-window
        • 13-python-pandas-sparse-data
        • 14-python-pandas-options
        • 15-python-pandas-time
      • 04-flask
        • 0001-flask-overview
      • 05-statistic-demo
        • 01-pandas-titanic
        • 02-pandas-restaurant
    • server
      • computer-science
        • 01-network-and-performance
        • 02-http1.1-vs-http2
        • 03 Http 3
        • 04 Http Cache
        • 05 Http Cookie
        • 06 Web Socket
        • 07 Websocket Message
        • 08-ssl-tls-npn-alpn
        • 09 SOCKS
        • 10 SOCKS 5 More
        • 11 UDT
        • 12-MIME
        • 13-transfer-encodings
        • 14-kqueue-epoll
        • 15-stream-socket
        • 16-datagram-socket
        • 17-unix-domain-socket
        • 18-base64-encoding
        • 19-domain-name-service
        • 20-haproxy-protocol
        • 21-sctp
        • 22-sctp-package-in-detail
        • 23-memcached-text-protocol
        • 24-memcached-binary-protocol
        • 25-redis-protocol
        • 26-mqtt-protocol
        • 27-stomp-protocol
      • linux
        • 01 That Is Kill
        • 02-du-and-df
      • server
        • nginx
          • 01-nginx-http2
          • 02-nginx-proxy-protocol
        • tomcat
          • 00001-tomcat-native-startup
        • wildfly
          • 00001-wildfly-startup
          • 00002-wildfly-config-resource
          • 00003-wildfly-domain
          • 00004-wildfly-app-deployment
          • 00005-wildfly-cluster-domain
    • spring
      • 01-springbase
        • 1. Spring MVC 中的http Caching
        • 2. @SessionAttributes 和 @SessionAttribute的区别
        • 5. Spring中的IOC容器
        • 6. 在Spring中创建Bean
        • 7. 依赖注入
        • 8. Bean作用域简介
        • 9. Spring Bean 的生命周期回调
        • 10. IOC扩展
        • 11. spring中的注解
        • 12. 组件扫描
        • 13. jsr330 annotation
        • 14. Spring的Environment接口
        • 15. 事件机制
        • 16. 资源resources
        • 17. Spring中的BeanWrapper
        • 18. SpEL
        • 19. AOP
        • 20. AspectJ注解
        • 21. 基于Schema的AOP
        • 22. AOP代理
        • 23. Spring中的@Configurable
        • 24. 深入探讨Spring多级缓存:原理与性能优化
      • 02-springBoot
        • 1. Spring Boot中的测试
        • 2. Spring Boot的TestRestTemplate使用
        • 3. Spring Boot中使用Swagger CodeGen生成REST client
        • 4. 将Spring Boot应用程序注册成为系统服务
        • 5. Spring Boot中的Properties
        • 6. Spring Boot中Spring data注解的使用
        • 7. Spring Boot中使用@JsonComponent
        • 8. Shutdown SpringBoot App
        • 9. Spring Boot 之Spring data JPA简介
        • 10. Spring Boot JPA 中transaction的使用
        • 11. Spring Boot JPA中关联表的使用
        • 12. Spring Boot JPA的查询语句
        • 13. Spring Boot JPA中使用@Entity和@Table
        • 14. Spring Boot JPA中java 8 的应用
        • 15. 在Spring Boot中加载初始化数据
        • 16. 在Spring Boot中自定义filter
        • 17. 在Spring Boot中使用内存数据库
        • 18. Spring Boot国际化支持
        • 19. 在Spring Boot使用H2内存数据库
        • 20. Spring Boot 自定义banner
        • 21. 使用spring boot创建fat jar APP
        • 22. Spring Boot devtool的使用
        • 23. SpringBoot @ConfigurationProperties详解
        • 24. 自定义spring boot的自动配置
        • 25. Spring Boot的exit code
        • 26. Spring Boot注解
        • 27. Spring Boot Admin的使用
        • 00028-Spring-Boot-Starters
        • 29. Spring Boot Actuator
        • 30. 使用maven和fat jar/war运行应用程序的对比
        • 31. Maven Wrapper简介
        • 32. 自定义parent POM
        • 00033-Change-Default-Port-in-Spring-Boot
        • 00034-Bootstrap-a-Simple-Application
        • 35. 在Spring Boot中配置web app
        • 38. 从Spring迁移到Spring Boot
        • 39. Spring Boot @EnableAutoConfiguration和@Configuration的区别
        • 00040-springboot-docker-image
        • 00041-springboot-reactive-web
        • 00042-springboot-HATEOAS
        • 00043-springboot-HATEOAS-Fundamentals
      • 03-springBoot3
        • 0001-what-is-new-in-springboot3
        • 0002-use-native-image-in-springboot3
      • 04-springCloud
        • 1. Spring Cloud OpenFeign Demo
        • 2. Spring Cloud sleuth with zipkin over RabbitMQ demo
    • tools
      • gradle
        • 01-gradle-kick-off
        • 02-gradle-build-script
        • 03-gradle-incremental-build
        • 04-gradle-task-in-depth
        • 05-gradle-vs-maven
        • 06-gradle-build-java-projects
        • 07-Gradle-Nexus-Publish-Plugin
      • java
        • 1. 5个2020年你不能不知道的java IDE神器
        • 02-jvm-jconsole
        • 03-jvm-jmap-jhat
        • 04-jvm-jstack
        • 05-jvm-jstat
      • maven
        • 01-apache-maven-lifecycle
        • 02-apache-maven-toolchains
        • 03-apache-maven-git-repository
        • 04-maven-OSSRH
      • protocolbuf
        • 01 Protocolbuf Guide
        • 02 Protocolbuf Detail
        • 03 Protobuf Encoding
由 GitBook 提供支持
在本页
  • 算法基础面试题(一)
  • 排序
  • 选择排序
  • 冒泡排序
  • 归并排序
  • 插入排序
  • 快速排序
  • count排序
  • 堆排序
  • 技巧
  • 二进制运算
  • 二分查找
  • 字符串匹配算法
  • 暴力匹配
  • KMP算法
  • Boyer-Moore 算法
  • Sunday 算法
  • Manacher 算法
  • Kadane 算法
  • 贪心算法

这有帮助吗?

  1. docs
  2. interview
  3. arithmetic
  4. more

001-arithmetic-01

算法基础面试题(一)

排序

选择排序

选择排序就是从数组中选择出来最大或者最小的元素,然后将其和队首或者队尾的元素进行交互。时间复杂度:O(n^2)

public class SelectionSort {
    public static void selectionSort(int[] arr) {
        int n = arr.length;

        // 外层循环控制选择排序的轮数
        for (int i = 0; i < n - 1; i++) {
            // 假设当前轮次的第一个元素是最小的
            int minIndex = i;

            // 内层循环在未排序的部分中找到最小元素的索引
            for (int j = i + 1; j < n; j++) {
                if (arr[j] < arr[minIndex]) {
                    minIndex = j;
                }
            }
            // 将找到的最小元素与当前轮次的第一个元素交换位置
            swap(arr, i, minIndex);
        }
    }
    // 辅助方法用于交换数组中的两个元素
    private static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

冒泡排序

冒泡排序的原理很简单,我们想象一下一个一个的气泡上浮的过程。排序共进行八轮,每一轮都会做两两比较,并将较大的元素右移,就像冒泡一下。

一轮结束之后,八个元素中最大的那个元素44将会移动到最右边。

然后再重复其他的几轮。最终得到一个完全排序的数组。

时间复杂度O(n^2)。

归并排序

归并排序简称Merge sort是一种递归思想的排序算法。这个算法的思路就是将要排序的数组分成很多小的部分,直到这些小的部分都是已排序的数组为止(只有一个元素的数组)。

然后将这些排序过的数组两两合并起来,组成一个更大一点的数组。接着将这些大一点的合并过的数组再继续合并,直到排序完整个数组为止。

时间复杂度为 O(nlogn)

public class MergeSort {
    public static void mergeSort(int[] arr, int low, int high) {
        if (low < high) {
            int mid = (high -low) / 2+ low;
            mergeSort(arr, low, mid);
            mergeSort(arr, mid + 1, high);
            merge(arr, low, mid, high);
        }
    }
    private static void merge(int[] arr, int low, int mid, int high) {
        int[] temp = new int[arr.length];
        int i = low;
        int j = mid + 1;
        int k = low;
        while (i <= mid && j <= high) {
            if (arr[i] <= arr[j]) {
                temp[k++] = arr[i++];
            } else {
                temp[k++] = arr[j++];
            }
        }
        while (i <= mid) { // 合并左边剩余元素
            temp[k++] = arr[i++];
        }
        while (j <= high) { // 合并右边剩余元素
            temp[k++] = arr[j++];
        }
        for (int l = low; l <= high; l++) { // 将合并后的结果拷贝回原数组
            arr[l] = temp[l];
        }
    }
}

插入排序

插入排序就是将要排序的元素插入到已经排序的数组中,从而形成一个新的排好序的数组。时间复杂度为 O(n^2)

public class InsertionSort {
    public static void insertionSort(int[] arr) {
        int n = arr.length;

        // 外层循环控制待插入的元素,从第二个元素开始
        for (int i = 1; i < n; i++) {
            // 当前要插入的元素
            int key = arr[i];
            // 内层循环用于在已排序的部分找到插入位置
            int j = i - 1;

            // 从后到前,移动比 key 大的元素向右,为 key 腾出插入位置
            while (j >= 0 && arr[j] > key) {
                arr[j + 1] = arr[j];
                j--;
            }

            // 插入 key 到正确的位置
            arr[j + 1] = key;
        }
    }

快速排序

快速排序也采用的是分而制之的思想。那么快速排序和归并排序的区别在什么地方呢?

归并排序是将所有的元素拆分成一个个排好序的数组,然后将这些数组再进行合并。

而快速排序虽然也是拆分,但是拆分之后的操作是从数组中选出一个中间节点,然后将数组分成两部分。

左边的部分小于中间节点,右边的部分大于中间节点。

然后再分别处理左边的数组合右边的数组。

public class QuickSort {
    public static void quickSort(int[] arr, int low, int high) {
        if (low < high) {
            int pivotIndex = partition(arr, low, high);
            quickSort(arr, low, pivotIndex - 1);
            quickSort(arr, pivotIndex + 1, high);
        }
    }
    private static int partition(int[] arr, int low, int high) {
        int pivot = arr[low];
        while (low < high) {
            while (low < high && arr[high] >= pivot) {
                high--;
            }
            arr[low] = arr[high];
            while (low < high && arr[low] <= pivot) {
                low++;
            }
            arr[high] = arr[low];
        }
        arr[low] = pivot;
        return low;
    }
}

count排序

count排序是一种空间换时间的算法,我们借助一个外部的count数组来统计各个元素出现的次数,从而最终完成排序。

public class CountingSort {
    public static void countingSort(int[] arr) {
        int n = arr.length;

        // 找到数组中的最大值,确定计数数组的大小
        int max = findMax(arr);

        // 初始化计数数组,大小为最大值加一
        int[] count = new int[max + 1];

        // 统计每个元素的出现次数
        for (int value : arr) {
            count[value]++;
        }

        // 根据计数数组重构原始数组
        int index = 0;
        for (int i = 0; i <= max; i++) {
            while (count[i] > 0) {
                arr[index++] = i;
                count[i]--;
            }
        }
    }

    private static int findMax(int[] arr) {
        int max = arr[0];
        for (int value : arr) {
            if (value > max) {
                max = value;
            }
        }
        return max;
    }
  • 计数排序的时间复杂度为 O(n + k),其中 n 是数组的长度,k 是数组中元素的范围(最大值减最小值加一)。

  • 计数排序是一种稳定的排序算法,适用于一定范围内的整数排序,但对于范围较大的整数或浮点数排序并不适用。

  • 计数排序是一种线性时间复杂度的排序算法,但需要额外的空间来存储计数数组。

堆排序

java中的PriorityQueue

public class HeapSort {
    public static void heapSort(int[] arr) {
      	//不包含n
        int n = arr.length;

        // 构建最大堆,从最后一个非叶子节点开始向上调整
        for (int i = n / 2 - 1; i >= 0; i--) {
            heapify(arr, n, i);
        }
        // 从堆顶依次取出最大元素,将堆重新调整为最大堆
        for (int i = n - 1; i > 0; i--) {
            // 将堆顶元素(最大值)与当前未排序部分的最后一个元素交换
            swap(arr, 0, i);
            // 调整剩余部分为最大堆,剩余部分不包含i
            heapify(arr, i, 0);
        }
    }

  //调整i这个节点,比较他跟他的子节点,并递归继续调整被交换的larget节点
    private static void heapify(int[] arr, int n, int i) {
        int largest = i; // 初始化最大值的索引为当前节点
        int leftChild = 2 * i + 1; // 左子节点的索引
        int rightChild = 2 * i + 2; // 右子节点的索引

        // 如果左子节点比当前节点大,则更新最大值的索引 ,为什么要小于n呢?是因为不包含n
        if (leftChild < n && arr[leftChild] > arr[largest]) {
            largest = leftChild;
        }
        // 如果右子节点比当前节点大,则更新最大值的索引
        if (rightChild < n && arr[rightChild] > arr[largest]) {
            largest = rightChild;
        }
        // 如果最大值的索引不等于当前节点,交换它们并递归调整子树
        if (largest != i) {
            swap(arr, i, largest);
            heapify(arr, n, largest);
        }
    }

    private static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

技巧

二维前缀和?

单调队列?

计算n/t的结果,如果有余数则+1,可以简化为(n+t-1)/t 非常巧妙

检查整数的类型:正整数,负整数,符号

int * int 的值需要用long来存储。

链表求倒数可以用栈

求最大公约数,碾转相除法:

    public int gcd(int a, int b) {
      return b != 0 ? gcd(b, a % b) : a;
  }

二进制运算

计算当前 x 和 y 的无进位相加结果:answer = x ^ y

计算当前 x 和 y 的进位:carry = (x & y) << 1

完成本次循环,更新 x = answer,y = carry

位运算: 抹去最右边的 1 : n = n & (n - 1);

保留最后一位:n&1

位运算 x & -x 取出 x 的二进制表示中最低位那个 1

~a 按位取反

i - (i >>> 1) 得到i的最高位的1

只出现一次的数组---异或,相同的数字异或结果是0,0和任何数字异或是数字本身

>>(带符号右移): 对于正数,>> 和 >>> 的效果是相同的。

>>>(无符号右移): 与 >> 不同,>>> 在移动过程中不管符号位,总是使用0来填充左侧的空位。

//数字范围按位与----选择数字范围的公共二进制前缀
    public int rangeBitwiseAnd(int left, int right) {

  while (left < right) {
            // 抹去最右边的 1
            right = right & (right - 1);
        }
        return right;
    }
    public int hammingWeight(int n) {
        int cnt=0;
    while(n!=0){
        cnt += (n & 1);
        n >>>= 1;
    }
    return cnt;
    }
//Brian Kernighan 算法
public class Solution {
    public int hammingWeight(int n) {
        int ret = 0;
      //移除最右的1
        while (n != 0) {
            n &= n - 1;
            ret++;
        }
        return ret;
    }
}

二分查找

二分查找特定的值:

while(left <= right) left=mid+1, right=mid-1;

当left,right边界条件都可能满足的情况下使用left <=right

while: left <=right的时候,一定是left=mid+1;right=mid-1; 否则会出现循环的情况。

当非搜索特定值的时候使用left < right, 如果 int mid=(left+right)/2;则 left=mid+1; right=mid 否则可能会出现遗漏的情况。

如果是left <=right,并且mid=(left+right)/2,或者mid=(left+right+1)/2 ----同样效果,不影响最后的值。的时候,那么最后的一次判断时候,left=right=mid, 可以根据最后一次的比较结果来判断最后返回left或者right。

当left,right边界条件部分可能满足的情况下使用left < right。会少一次边界情况的判断。

如果是left < right, 如果mid=(left+right)/2,(更新时候left=mid+1, right=mid),那么最后的mid=left, mid=right-1。会导致mid有可能到不了right的位置,从而少判断一次情况。如果在动态判断比较中已经用用到了right的值,那么可以忽略。

如果是left < right, 如果mid=(left+right+1)/2,(更新时候left=mid, right=mid-1),那么最后的mid=right,mid=left+1,会导致mid可能到不了最左边的情况。从而少判断一次情况。如果在动态判断中用到了left的值,那么可以忽略。

这两种情况下,需要判断最后一次未比较的判断是通过哪个判断条件引起的。

在left< right的情况下,什么时候用mid=(left+right)/2,什么时候用mid=(left+right+1)/2呢?

主要看比较条件,看在在比较条件下加一,还是不加一是否仍然满足比较条件。选择仍然满足条件的那个,然后对mid进行调整。

   public int searchInsert(int[] nums, int target) {
        int left=0; 
        int right = nums.length-1;
        while(left <=right){
            int mid=(left+right)/2;
            if(nums[mid]<target){
                left=mid+1;
            }else{
                right=mid-1;
            } 
        }
        return left; 
    }
    
    // 两次二分查找,分开查找第一个和最后一个
  // 时间复杂度 O(log n), 空间复杂度 O(1)
  // [1,2,3,3,3,3,4,5,9]
  public int[] searchRange2(int[] nums, int target) {
    int left = 0;
    int right = nums.length - 1;
    int first = -1;
    int last = -1;
    // 找第一个等于target的位置
    while (left <= right) {
      int middle = (left + right) / 2;
      if (nums[middle] == target) {
        first = middle;
        right = middle - 1; //重点
      } else if (nums[middle] > target) {
        right = middle - 1;
      } else {
        left = middle + 1;
      }
    }

    // 最后一个等于target的位置
    left = 0;
    right = nums.length - 1;
    while (left <= right) {
      int middle = (left + right) / 2;
      if (nums[middle] == target) {
        last = middle;
        left = middle + 1; //重点
      } else if (nums[middle] > target) {
        right = middle - 1;
      } else {
        left = middle + 1;
      }
    }

    return new int[]{first, last};
  }

字符串匹配算法

暴力匹配

KMP算法

KMP**算法在大规模文本匹配中具有较高的效率,尤其在一些大数据处理场景下表现优越。

  • KMP算法步骤:

    1. 初始化文本串指针 i 和模式串指针 j。

    1. 若当前字符匹配,则 i 和 j 同时后移。

    1. 若当前字符不匹配,根据 next[j] 调整 j 的位置。

    1. 重复步骤2-3,直到找到匹配或文本串遍历完。

 public static int KmpSearch(String str1, String str2) {
        int[] next = KMP_next(str2);
        //遍历
        for (int i = 0, j = 0; i < str1.length(); i++) {
            while (j > 0 && str1.charAt(i) != str2.charAt(j)) {
                j = next[j - 1];
            }
            if (str1.charAt(i) == str2.charAt(j)) {
                j++;
            }
            if (j == str2.length()) {
                return i - j + 1;
            }
        }
        return -1;
    }

    //获取到一个字符串的部分匹配值
    public static int[] KMP_next(String dest) {
        //创建一个数组next,保存部分匹配值
        int[] next = new int[dest.length()];
        next[0] = 0;//如果字符串是长度为1 部分匹配值就是0
        for (int i = 1, j = 0; i < dest.length(); i++) {
            //当dest.charAt(j) != dest.charAt(i),我们需要从next[j-1]获取新的j
            //直到我们发现有dest.charAt(j) == dest.charAt(i)成立才停止
            while (j > 0 && dest.charAt(j) != dest.charAt(i)) {
                j = next[j - 1];
            }
            //当dest.charAt(j) == dest.charAt(i)满足时,部分匹配值就是+1
            if (dest.charAt(j) == dest.charAt(i)) {
                j++;
            }
            next[i] = j;
        }
        return next;
    }

Boyer-Moore 算法

Boyer-Moore 算法是一种用于字符串搜索的高效算法,于 1977 年由 Robert S. Boyer 和 J Strother Moore 提出。该算法在实际应用中通常比其他字符串搜索算法更快。

Boyer-Moore 算法的主要思想是从右到左进行字符串匹配,而不是从左到右。算法利用两个规则来跳过不匹配的字符,从而加速搜索:

  1. 坏字符规则(Bad Character Rule): 当发现不匹配的字符时,算法会将模式中最右边的该字符与文本中匹配位置对齐,从而跳过一些不可能匹配的位置。

  2. 好后缀规则(Good Suffix Rule): 当发现不匹配的字符时,算法会查找模式中与文本匹配的最右边的部分,并将其与文本中匹配位置对齐,跳过一些不可能匹配的位置。

Sunday 算法

Sunday 算法是一种字符串匹配算法,用于在文本中查找模式的出现位置。它由Daniel M. Sunday于1990年提出,是一种线性时间复杂度的字符串匹配算法,类似于Boyer-Moore算法。

Sunday 算法的基本思想是从左到右比较文本和模式,当发现不匹配的字符时,尽量将模式向右移动,使得下一个字符对齐文本中的下一个字符。具体而言,当发现不匹配时,根据下一个字符在模式中的位置,决定模式的移动距离。

以下是 Sunday 算法的基本步骤:

  1. 从左到右比较文本和模式。

  2. 如果发现不匹配,找到文本中与模式最右端对齐的字符的下一个字符(称为关键字符)。

  3. 根据关键字符在模式中的位置,决定模式向右移动的距离。

Manacher 算法

Manacher 算法是一种用于查找最长回文子串的线性时间复杂度算法。

Manacher 算法的关键在于利用已知的回文串信息,避免了重复计算。它维护一个数组 P,其中 P[i] 表示以字符 s[i] 为中心的最长回文串的半径长度。通过动态规划的方式计算 P 数组,从而得到最长回文子串的位置和长度。

以下是 Manacher 算法的基本步骤:

  1. 预处理字符串,使其变成奇数长度。

  2. 初始化 P 数组。

  3. 以每个字符为中心,向两侧扩展并更新 P 数组。

  4. 根据 P 数组得到最长回文子串。

Manacher 算法的时间复杂度为 O(n),其中 n 是字符串的长度。由于其高效性和简洁性,Manacher 算法在解决回文串相关问题时被广泛使用。

最长回文半径和最长回文子串长度之间的关系:int maxLength = p[i]-1。maxLength表示最长回文子串长度。

最长回文子串的起始索引int index = (i - p[i])/2

public class ManacherAlgorithm {

    public static String longestPalindrome(String s) {
        if (s == null || s.length() == 0) {
            return "";
        }

        // 预处理字符串,使其变成奇数长度
        String processedString = preprocessString(s);

        int n = processedString.length();
        int[] p = new int[n];
        int center = 0, right = 0; // 当前回文串的中心和右边界

        for (int i = 1; i < n - 1; i++) {
            int mirror = 2 * center - i; // 计算 i 关于 center 的对称位置
            if (right > i) {
                p[i] = Math.min(right - i, p[mirror]);
            }
            // 尝试扩展回文串
            while (processedString.charAt(i + p[i] + 1) == processedString.charAt(i - p[i] - 1)) {
                p[i]++;
            }
            // 更新 center 和 right
            if (i + p[i] > right) {
                center = i;
                right = i + p[i];
            }
        }
        // 找到最长回文子串的中心和半径
        int maxLen = 0;
        int centerIndex = 0;
        for (int i = 1; i < n - 1; i++) {
            if (p[i] > maxLen) {
                maxLen = p[i];
                centerIndex = i;
            }
        }

        // 提取最长回文子串
        int start = (centerIndex - maxLen) / 2;
        return s.substring(start, start + maxLen);
    }

    private static String preprocessString(String s) {
        StringBuilder sb = new StringBuilder("#");
        for (char c : s.toCharArray()) {
            sb.append(c).append("#");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String s = "babad";
        System.out.println("Longest Palindrome: " + longestPalindrome(s));
    }
}

Kadane 算法

Kadane 算法的关键点在于,对于数组中的每个元素,我们在计算当前最大和时要考虑包含该元素的情况。如果当前最大和变为负数,就说明前面的子数组和对后续元素的贡献为负,所以可以将当前最大和重置为当前元素。

public static int maxSubArraySum(int[] nums) {
    if (nums == null || nums.length == 0) {
        return 0;
    }
    int maxCurrent = nums[0];
    int maxGlobal = nums[0];
    for (int i = 1; i < nums.length; i++) {
        maxCurrent = Math.max(nums[i], maxCurrent + nums[i]);
        maxGlobal = Math.max(maxGlobal, maxCurrent);
    }
    return maxGlobal;
}

public static void main(String[] args) {
    int[] nums = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
    System.out.println("Maximum Subarray Sum: " + maxSubArraySum(nums));
}

贪心算法

贪心算法的特点包括:

  1. 局部最优解: 在每一步选择中都采取当前状态下的最优策略,即局部最优解。

  2. 不回溯: 一旦做出了选择,在当前状态下不再改变。

  3. 无法保证全局最优解: 贪心算法的策略可能无法得到全局最优解,因为在做出每个局部选择时,无法预测之后的状态。

贪心算法常见的应用包括:

  • 最小生成树问题(Minimum Spanning Tree): Kruskal 算法和 Prim 算法。

  • 最短路径问题(Shortest Path): Dijkstra 算法。

  • 背包问题(Knapsack Problem): 每次选择当前价值密度最高的物品放入背包。

上一页more下一页002-arithmetic-02

最后更新于1年前

这有帮助吗?