Code Monkey home page Code Monkey logo

Comments (3)

yanglbme avatar yanglbme commented on August 26, 2024

有问题的,因为前面遍历过的字符都放入 map 中了,你直接使用 map.get(chars[q]) + 1 获得下标,并赋给 p,p 指针就可能往回走了。我那里举了个例子 abba,如果是下面这种情况。

a b b a
    ↑ ↑
    p q

p 此时指向第二个 b,q 指向最后的 a,此时 map中包含 chars[q],即包含a,此时你那样赋值的话,p=0+1,即p=1,p指针往回走了。

from leetcode.

yanglbme avatar yanglbme commented on August 26, 2024

要确保 p,q 之间不包含重复字符,你p指针回溯过后,p,q之间就包含两个字符b了。

from leetcode.

cnkeeper avatar cnkeeper commented on August 26, 2024

有问题的,因为前面遍历过的字符都放入 map 中了,你直接使用 map.get(chars[q]) + 1 获得下标,并赋给 p,p 指针就可能往回走了。我那里举了个例子 abba,如果是下面这种情况。

a b b a
    ↑ ↑
    p q

p 此时指向第二个 b,q 指向最后的 a,此时 map中包含 chars[q],即包含a,此时你那样赋值的话,p=0+1,即p=1,p指针往回走了。

豁然开朗,谢谢回复!

from leetcode.

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.