Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug] 22. Generate Parentheses returns 'Wrong Answer' despite passing test cases in Leetcode #3485

Closed
@njxue

Description

@njxue
Input: n = 3Expected Output: ["((()))","(()())","(())()","()(())","()()()"]

It flags the output["()()()","()(())","(())()","(()())","((()))"] as incorrect. The order of the generated parantheses should not matter.

For reference, this was the code (in Java) that generated the failed test case:

class Solution {    public List<String> generateParenthesis(int n) {        List<String> parantheses = new ArrayList<>();        helper(n, n, "", parantheses);        return parantheses;    }    public void helper(int numOpenRemaining, int numCloseRemaining, String p, List<String> parantheses) {        if (numOpenRemaining == 0 && numCloseRemaining == 0) {            parantheses.add(p);            return;        }        if (numOpenRemaining < numCloseRemaining) {            helper(numOpenRemaining, numCloseRemaining - 1, p + ")", parantheses);        }        if (numOpenRemaining > 0) {            helper(numOpenRemaining - 1, numCloseRemaining, p + "(", parantheses);        }    }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp