Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

面试题3 题目二部分测试用例过不了 #85

Open
amyZhoucc opened this issue May 1, 2021 · 3 comments
Open

面试题3 题目二部分测试用例过不了 #85

amyZhoucc opened this issue May 1, 2021 · 3 comments

Comments

@amyZhoucc
Copy link

[0, 0, 1, 2, 4, 5, 6, 7, 8, 9],这样的样例从第一次二分的时候,就发现不了正确的重复区间了,因为第一次遍历时候,发现[0, 4]范围内是5个数字,所以认为重复出现在[5, 9],所以出现了错误。想问一下这个要如何解决?
我想到一种方法:对[0, 4]找到的该区间的数字进行求和,如果出现了5:5的情况,且求和的值也符合预期,那么才可能会出现在后半部分(反例,[0, 0, 3, 3, 4], 5:5, 且求和的值也还是10= [0, 4]的总和)

@orangewangjie
Copy link

比如{1,1,2,2,5,6,7,8,9} 本来的代码应该就找不出答案

@JiaoZK
Copy link

JiaoZK commented Aug 7, 2021

{2,2,3,3,5,5,6,6} 这种肯定找不到

@1234cas
Copy link

1234cas commented Aug 30, 2022

[0, 0, 1, 2, 4, 5, 6, 7, 8, 9],这样的样例从第一次二分的时候,就发现不了正确的重复区间了,因为第一次遍历时候,发现[0, 4]范围内是5个数字,所以认为重复出现在[5, 9],所以出现了错误。想问一下这个要如何解决? 我想到一种方法:对[0, 4]找到的该区间的数字进行求和,如果出现了5:5的情况,且求和的值也符合预期,那么才可能会出现在后半部分(反例,[0, 0, 3, 3, 4], 5:5, 且求和的值也还是10= [0, 4]的总和)

该题题目是在n+1长度的数组中的数组在1~n范围内。所以这个本就不符合题意

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants