Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

binary-search/Solution.java: prints -1 when the target is the last element (`9 1 3 5 7 9`) or in a 1-element list (`5 5`)

未关闭
#26 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@tanujb03 已经在做这个了。

开始于 2026年10月10日。

  • #30 来自 @tanujb03 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
22/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

The bug is in problems/binary-search/Solution.java, where the search reports -1 once it narrows to a single position. Check linked pull request #30 first, since work is already under way. Done means 9 1 3 5 7 9 prints 4, 5 5 prints 0, and 3 1 3 prints 1, with those cases added to cases.txt and python3 run.py binary-search passing.

由索引模型根据 Issue 内容生成。

描述

bug good first issue

What I did

  1. Fresh checkout of main, JDK 17.
  2. Compile the Java solution and run it on a few inputs (the input is one line: the target, then the sorted list):
cd problems/binary-search
javac Solution.java
echo "9 1 3 5 7 9" | java Solution
echo "5 5"         | java Solution
echo "3 1 3"       | java Solution
echo "3 1 3 5"     | java Solution
  1. For comparison, the Python solution: echo "9 1 3 5 7 9" | python3 solution.py

What I expected
The problem README says: "Print the position (starting from 0) of the target in the list, or -1 if it isn't there." (problems/binary-search/README.md)

So 9 1 3 5 7 9 should print 4, 5 5 should print 0, 3 1 3 should print 1, and 3 1 3 5 should print 1.

What happened instead

9 1 3 5 7 9  -> -1   (expected 4)
5 5          -> -1   (expected 0)
3 1 3        -> -1   (expected 1)
3 1 3 5      -> 1    (correct)

The target is found, then reported as missing, whenever the search narrows to a single position. The Python and C++ solutions print the right answer for all of these. python3 run.py binary-search passes today because none of the cases in cases.txt ends the search on a single remaining position.

Environment
code-corner main @ 0c95800, JDK 17, Windows 11.

I'd like to work on the fix for this, and add the failing inputs to cases.txt as the Contributing section asks.

主要语言
Python
星标
1
派生
6
平均合并
17 小时 52 分钟
30 天内合并 PR
14

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

techcsispit/code-corner 的其他 Issue

查看 techcsispit/code-corner 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。