Code Monkey home page Code Monkey logo

Comments (4)

jaydu666 avatar jaydu666 commented on May 20, 2024 1

from leetcode-go.

halfrost avatar halfrost commented on May 20, 2024

@jaydu666 您好,你标记的这里判断条件是 == 是没有问题的。理由如下:

当条件进入到 else 里面的时候,说明右窗口已经无法往右移动了,这个时候 count == len(t),窗口中已经完全包含了 t 字符串。这时窗口中左边界的字母有 2 种情况:

    1. 左边界的字母是 t 中的字母。
    1. 左边界的字母不是 t 中的字母。

如果是情况 1,那么直接移动左边界,缩小窗口即可。如果是情况 2,那么左边界的 freq 一定和 t 中这个字母的 freq 相等,因为此时 count == len(t),那么这个时候要移动左边界,要把 count--。所以这里判断 freq 是否相等是正确的。

你要是把代码改成 <= 提交,代码也是可以通过的,因为 <= 是 == 的 必要不充分条件。所以这里直接写成 == 更准确一些。

from leetcode-go.

jaydu666 avatar jaydu666 commented on May 20, 2024

from leetcode-go.

halfrost avatar halfrost commented on May 20, 2024

你写 <= 这题也能过,不过不准确。

没事,有问题随时提出来一起交流哈~💪🏻

from leetcode-go.

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.