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`)
維護者通常 1 天內回覆
評估
研究方向
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 內容生成。
描述
What I did
- Fresh checkout of
main, JDK 17. - 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
- 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
- 平均合併
- 21 小時 9 分鐘
- 30 天內合併 PR
- 18
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
techcsispit/code-corner 的其他 Issue
-
prime/solution.java doesn't compile: public class PrimeCheck in solution.java, README requires Solution.java with a Solution class可能已有人在做 @tanujb03 於 4 天前認領。 未關閉bug good first issue
難度 1/5 1 小時以內 新手友好度 82/100
techcsispit/code-corner#35 ·
維護者通常 1 天內回覆
-
Failed compilations always report 0.000 seconds可能已有人在做 @Nik-2208 於 1 天前認領。 未關閉bug good first issue
難度 2/5 1-3 小時 新手友好度 35/100
techcsispit/code-corner#37 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Add test cases to a problem可能已有人在做 @25crns 於 11 天前認領。 未關閉good first issue tests
techcsispit/code-corner#2 · 3 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Solve a problem in a language it doesn't have yet可能已有人在做 @praseedbhat 於 5 天前認領。 未關閉feature good first issue
難度 2/5 1-3 小時 新手友好度 52/100
techcsispit/code-corner#1 · 6 則留言 · 已指派 4 人 ·
維護者通常 1 天內回覆
查看 techcsispit/code-corner 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 68/100
Deltares/imod-python#1940 ·
維護者通常 1 天內回覆
-
effort: low prio: low ready
難度 1/5 1 小時以內 新手友好度 82/100
digitalfabrik/integreat-cms#4621 ·
維護者通常 5 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
ioos/compliance-checker#1375 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆