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

Weird bug on "Construct the Rectangle" problem #36

Open
weebao opened this issue Jan 12, 2025 · 0 comments
Open

Weird bug on "Construct the Rectangle" problem #36

weebao opened this issue Jan 12, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@weebao
Copy link
Member

weebao commented Jan 12, 2025

Log:

Traceback (most recent call last): File "/code/tmp8dl2laag.py", line 60, in run_tests passed = 
compare_results(result, test['expected']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
File "/code/tmp8dl2laag.py", line 25, in compare_results expected = eval(expected); 
return result[0]*result[1] == expected[0]*expected[1] and result[0] >= result[1] 
    and abs(result[0]-result[1]) <= abs(expected[0]-expected[1]) ~~~~~~^^^ IndexError: list index out of range

Reproduction:
Go to "Construct the Rectangle" and execute the following code:

class Solution:
    def constructRectangle(self, area: int) -> List[int]:
        min_diff = float("inf")
        res = []
        L_cache = set()
        for W in range(1, area):
            if W in L_cache:
                break
            if area % W != 0:
                continue
            L = area / W
            L_cache.add(L)
            if L - W < min_diff:
                min_diff = L - W
                res = [L, W]
        return res
@weebao weebao added the bug Something isn't working label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants