220. Generate Parentheses (Count)

MediumStringString

Given n pairs of parentheses, return the number of distinct well-formed parentheses strings that can be generated. This equals the n-th Catalan number.

Input: A non-negative integer n.

Output: Integer — count of valid combinations.

Examples

Example 1
Input: 3
Output: 5
Explanation: 5 valid combinations for n=3.
Example 2
Input: 1
Output: 1
Explanation: '()'.
Example 3
Input: 0
Output: 1
Explanation: Empty string is one valid combination.

Constraints

Asked by

AmazonBloombergMicrosoftGoogleAdobeInfosys
Solve this problem in the editor →