Coder Social home page Coder Social logo

2016校招18似乎有错吧 about cs-notes HOT 10 CLOSED

cyc2018 avatar cyc2018 commented on May 18, 2024
2016校招18似乎有错吧

from cs-notes.

Comments (10)

CyC2018 avatar CyC2018 commented on May 18, 2024

len 包含了 len2的信息

from cs-notes.

SpecialYang avatar SpecialYang commented on May 18, 2024

你的len是取得最小值,怎么会包含len2,测试用例 aa bb 1, 1000 你看你输出的是什么

from cs-notes.

CyC2018 avatar CyC2018 commented on May 18, 2024

最小长度就是 len2 和 s2.length() 的最小值,这是没错的。

from cs-notes.

CyC2018 avatar CyC2018 commented on May 18, 2024

这个笔记没加在 README 中,还没整理完,忘记在仓库中删除了,没想到会有人看…现在不建议看

from cs-notes.

SpecialYang avatar SpecialYang commented on May 18, 2024

哈哈,知道了,不过你的这个代码还是有误啊,测试用例aa bb 1 100,输出竟然是27,怎么可能呢。。应该是很大很大的

from cs-notes.

CyC2018 avatar CyC2018 commented on May 18, 2024

我现在在坐车,回去的时候再看一下。这个题目本身就比较坑,没有描述清楚,我也是参考别人的代码才搞懂…

from cs-notes.

SpecialYang avatar SpecialYang commented on May 18, 2024

好的,没事,我参考你的思路改了一点

public static int getCount(String str1, String str2, int len1, int len2){
        int[] subtractArr = new int[len2];
        char c1, c2;
        for(int i = 0; i < len2; i++){
            c1 = i < str1.length() ? str1.charAt(i) : 'a' - 1;
            c2 = i < str2.length() ? str2.charAt(i) : 'a' - 1;
            subtractArr[i] = c2 - c1;
        }
        int ans = 0;
        for(int i = len1; i <= len2; i++){
            for(int j = 0; j < i; j++){
                ans = (ans + ((int)(subtractArr[j] * Math.pow(26, i - j - 1))) % MOD) % MOD;
            }
        }
        return ans - 1;
    }

from cs-notes.

CyC2018 avatar CyC2018 commented on May 18, 2024

@specialYY 你提供的测试用例,aa bb 1 1000 输出结果为 27 是正确的。虽然你指定了 len2 的长度为 1000,但是字符串最大长度为 2,因此超过 2 的部分就不需要考虑了。

题目没有明确说明长度超过字符串的长度时应该怎么处理,怎么解释都可以,我的代码也是可以通过的。我想,牛客网的在线编程系统应该只有 len2 <= str2.length() 的测试用例,所以两种解法都可以通过。

from cs-notes.

SpecialYang avatar SpecialYang commented on May 18, 2024

也是题目没说清若len2大于字符串长度怎么处理。刚看了一下,又更新了很多资料,都是干货啊。这得花多少时间整理啊!

from cs-notes.

CyC2018 avatar CyC2018 commented on May 18, 2024

@specialYY 从去年十一月份开始准备到现在

from cs-notes.

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.