Git Product home page Git Product logo

Comments (5)

jeff-liu14 avatar jeff-liu14 commented on July 24, 2024

可以把原地数组的核心代码讲解一下吗

from algorithm007-class02.

liuzhenbin96 avatar liuzhenbin96 commented on July 24, 2024

可以把原地数组的核心代码讲解一下吗

核心代码(Java示例):
resIndex = 0;
for (int i = 0; i < len; i++) {
if(判断条件) {
arr[resIndex++] = arr[i];
}
}

from algorithm007-class02.

Zts0hg avatar Zts0hg commented on July 24, 2024
    在可以创建额外数组,即两个数组的情况下,只需要一个指针,符合条件的添加到新数组中,新数组作为结果返回。
    在要求原地修改,即使用原地数组的情况下,相当于把两个数组放在了一起。由于其中一个数组的信息量在这种情况下会比另一个数组信息量小,比如排序数组去重中,新数组是原数组的子集;在移动零中,新数组是提取出原数组的非零元,(我们已知用0填空其他位置)。所以原数组的指针走过的地方可以被覆盖,即可以用作新数组的存储空间。
    指针的数量相当于需要获取的信息的数量。双指针分别对应新旧数组的逻辑位置(毕竟物理位置上重合)。

from algorithm007-class02.

dinghongchao avatar dinghongchao commented on July 24, 2024

就是在原有数组上进行操作不开辟新的空间

from algorithm007-class02.

xuguangyi avatar xuguangyi commented on July 24, 2024

体会:尽量抛弃工程代码中使用高级数据结构的依赖习惯,多从问题本身触发。

from algorithm007-class02.

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.