Comments (4)
题目有要求:在一个长度为n+1的数组里的所有数字都在1到n的范围内,所以数组中至少有一个数字是重复的。
from codinginterviewchinese2.
面试题三解法二确实是有问题的,比如针对测试用例
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.
@gao-lex 你的数组有问题,数组的长度是10,所以所有的数字应该都在1到9范围内,没有0
from codinginterviewchinese2.
@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)
- 面试题60 第二种解法是不是有问题啊,会int溢出
- Partition function has extremely bad performance for array with identical values
- 面试题14剪绳子动态规划 HOT 5
- #面试题37
- 面试题30 是否有必要总是将min(value, m_min.top())压入辅助栈中? HOT 1
- 面试68题答案错误
- 面试题17的本题扩展
- c
- 面试题54:二叉搜索树的第K大节点 HOT 1
- 第二版勘误
- Singleton
- 面试题19的题目有误? HOT 1
- 面试题3 题目二部分测试用例过不了 HOT 3
- pro
- 面试题10:斐波那契数列测试用例过不去 HOT 1
- 51题,数组中的逆序对
- List.cpp 头文件 #include "list.h" 有误
- How to build and run CommonParentInTree.cpp on macOS?
- Hu
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codinginterviewchinese2.