4th LeetCode:22. Generate Parentheses

Shu-Yu Huang
1 min readApr 16, 2020

--

Solution1 Exceed Time Limit

We were demanded to create a system checking the parentheses is valid in a series of K pairs of parentheses.

The definition of “valid” is:
1. The amount of “(”s and “)”s must be equal.
2. The amount of “(” should be more than “)“ in the LHS of a “)”
3. No “)” in the left-most, and no “(” in the right-most.

The solution I gave was as follows:

  1. List all possible combinations of K “(”s and K “)”s excluding those “)” in the left-most or “(” in the right-most.
  2. Examine each combination:
    a. Exclude repeated combinations
    b. Exclude which has more “)”s than “(”s in LHS of any “)”

This solution was easy, but consume too much time, need to be revised

https://leetcode.com/playground/7mkiEkLg

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Shu-Yu Huang
Shu-Yu Huang

Written by Shu-Yu Huang

AI engineer in Taiwan AI Academy| Former process engineer in TSMC| Former Research Assistance in NYMU| Studying few-shot-learning and GAN

No responses yet

Write a response