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`)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 22/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 1
- Fork
- 6
- Merge trung bình
- 17 giờ 52 phút
- Pull request đã merge (30 ngày)
- 14
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của techcsispit/code-corner
-
prime/solution.java doesn't compile: public class PrimeCheck in solution.java, README requires Solution.java with a Solution classCó thể đã có người làm @tanujb03 đã nhận 1 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
techcsispit/code-corner#35 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Prime solution in C++ incorrectly returns true for some composite numbersCó thể đã có người làm @paramsj đã nhận 1 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 25/100
techcsispit/code-corner#38 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Failed compilations always report 0.000 secondsCó thể đã có người làm @Shivangi-singh18 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
techcsispit/code-corner#37 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
run.py: Python solutions are skipped on Windows when run via python instead of python3Có thể đã có người làm @tanujb03 đã nhận 2 ngày trước. Đang mởbug good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 15/100
techcsispit/code-corner#29 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fibonacci/solution.c: prints negative numbers for n of 47 or more (F(90) prints -1581614984)Có thể đã có người làm @tanujb03 đã nhận 2 ngày trước. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
techcsispit/code-corner#27 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của techcsispit/code-corner
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
KalicoCrew/kalico#1012 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
esphome/esphome.io#7657 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
VNG-Realisatie/gemma-zaken#2658 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
comp/gateway comp/plugins duplicate P3 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NousResearch/hermes-agent#137019 ·
Maintainer thường phản hồi trong vòng 1 ngày