Giter Club home page Giter Club logo

Comments (4)

ridiculousJoe avatar ridiculousJoe commented on July 21, 2024

题目有要求:在一个长度为n+1的数组里的所有数字都在1到n的范围内,所以数组中至少有一个数字是重复的。

from codinginterviewchinese2.

gao-lex avatar gao-lex commented on July 21, 2024

面试题三解法二确实是有问题的,比如针对测试用例

void test11()
{
    int numbers[] = { 0, 1, 2, 0, 4, 5, 6, 7, 8, 9 };
    int duplications[] = { 0 };
    test("test11", numbers, sizeof(numbers) / sizeof(int), duplications, sizeof(duplications) / sizeof(int));
}

mid = 4
然而在[0,4]之间应该有5个数,确实也有5个数。
在[5,9]之间也是应该有5个数,确实有5个数。
您所实现的这个算法在这个样例下的运行结果是:

test11 FAILED.

from codinginterviewchinese2.

chennuo0125-HIT avatar chennuo0125-HIT commented on July 21, 2024

@gao-lex 你的数组有问题,数组的长度是10,所以所有的数字应该都在1到9范围内,没有0

from codinginterviewchinese2.

1234cas avatar 1234cas commented on July 21, 2024

@gao-lex 你的数组有问题,数组的长度是10,所以所有的数字应该都在1到9范围内,没有0

他这个测试用例是leetcode的上的,leetcode的题目是0~n-1范围,就是原题题解是没问题的,但是不能直接套这个题解去解leetcode的题

该题题解无法解决0重复出现应该是因为在
if (count > (mid - start + 1)) end = mid
如果start为0 会导致count = mid
无法正确二分

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.