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

Added a more efficient solution for the Valid_Parentheses LeetCode Problem #476

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

danieldotwav
Copy link

@danieldotwav danieldotwav commented Jan 16, 2024

Pull Request Template

Description

A robust C++ solution for validating parentheses in strings. This project features a well-tested algorithm that handles different types of parentheses, including (), {}, and []. It is designed to cover a wide range of scenarios, from simple to complex nested structures, ensuring the correct ordering and pairing of parentheses.

Put check marks:

Have you made changes in README file ?

  • Added problem & solution under correct topic.
  • Specified Space & Time complexity.
  • Specified difficulty level, tag & Note(if any).

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.

// Create a string for each test case
    std::string label, test_string;
    std::unordered_map<std::string, std::string> test_cases = {
        {"Test 1:", "()"},           // Simple valid case
        {"Test 2:", "{}[]()"},       // Mixed types, valid
        {"Test 3:", "(]"},           // Mismatched types
        {"Test 4:", "([)]"},         // Valid types but wrongly ordered
        {"Test 5:", "(((())))"},     // Nested, valid
        {"Test 6:", "("},            // Single, unmatched
        {"Test 7:", "){"},           // Invalid start with closing
        {"Test 8:", "(()){[()]}"},   // Complex, valid
        {"Test 9:", ""},             // Empty string
        {"Test 10:", "((()(())))"},  // More complex nested, valid
        {"Test 11:", "([{}])"},      // Mixed types nested, valid
        {"Test 12:", "(}"},          // Mismatched pair
        {"Test 13:", "([]{}"},       // Missing closing
        {"Test 14:", "([)]{}"},      // Mixed types with wrong order
        {"Test 15:", "((((((("},     // Multiple unmatched opening
        {"Test 16:", "))))))"},      // Multiple unmatched closing
        {"Test 17:", "([[[{{{{"},    // Multiple unmatched opening of different types
        {"Test 18:", "}]]]))"},      // Multiple unmatched closing of different types
        {"Test 19:", "(())(()"},     // Partially matched
        {"Test 20:", "[([])](){}"}   // Complex, valid with all types
    };

    // Access each test case and print the result
    for (const auto& pair : test_cases) {
        const std::string& label = pair.first;
        const std::string& test_string = pair.second;
        std::cout << std::left << std::setw(TEST_NUMBER_WIDTH) << label << std::setw(TEST_STRING_WIDTH)
            << test_string << std::setw(OUTCOME_WIDTH) << (isValid(test_string) ? "Valid" : "Invalid") << '\n';
    }

Make sure all below guidelines are followed else PR will get Reject:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code so that it is easy to understand
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Copy link

welcome bot commented Jan 16, 2024

I can tell this is your first pull request! Thank you I'm so honored. 🎉🎉🎉 I'll take a look at it ASAP!

@danieldotwav danieldotwav changed the title Added Solution Added a more efficient solution for the Valid_Parentheses LeetCode Problem Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants