Giter Club home page Giter Club logo

Comments (2)

zhedahht avatar zhedahht commented on May 23, 2024

从0到n-1里面的任意一个数字i,如果开始它不在下标为i的位置,通过交换把它放到下标为i的位置。如果下次再遇到值为i的数字,当我们再想把它交换到下标为i的位置时,就会发现下标为i的位置已经有一个值为i的数字,就找到一个重复的数字了。

我们通过这这种交换,把从0到n-1的每个数字都放到和值相等的下标的位置。一个数字最多只需要交换两次。所以交换的次数是O(n)。

from codinginterviewchinese2.

 avatar commented on May 23, 2024

明白了,谢谢。

from codinginterviewchinese2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.