Want to know:
最简单的做法是通过swap把每个数字放到自己的位置上,比如5就放到idx = 4的地方,第一个不符合的位置就是缺的位置因为每个数字最多通过2次就能换到适当的位置上所以时间是O(n),空间是O(1)也可以用union-find做,但是代码过于复杂
Get a detailed, AI-powered explanation for this question and thousands more on StudyFetch.
Get the Answer for FreeHow StudyFetch Helps You Master This Topic
AI-Powered Answers
Get instant, detailed explanations powered by AI that understands your course material.
Deep Understanding
Go beyond surface-level answers with step-by-step breakdowns and examples.
Personalized Learning
Spark.E adapts to your learning style and helps you connect ideas.
Practice & Test
Turn any question into flashcards, quizzes, and practice tests to solidify your knowledge.