Back to Browse

Valid Parenthesis String | LeetCode 678 | Programming Tutorials

2.3K views
Apr 17, 2020
14:03

In this tutorial, I have explained valid parentheses string LeetCode solution in java using Two Stacks. LeetCode 30 Day Challenge PlayList - https://www.youtube.com/watch?v=-I1pUv57WG8&list=PLUg9hRlm7gxT8mrwa_648iC8Ah42E0W1o Valid Parentheses String Java Code - https://webrewrite.com/valid-parentheses-string/ Given a string containing only three types of characters: '(', ')' and '*'. Write a function to check whether this string is valid. We define the validity of a string by these rules: Any left parenthesis '(' must have a corresponding right parenthesis ')'. Any right parenthesis ')' must have a corresponding left parenthesis '('. Left parenthesis '(' must go before the corresponding right parenthesis ')'. '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string. An empty string is also valid. Example 1: Input: "*())" Output: True (The start will be treated as '(') Example 2: Input: "(*)" Output: True (The star will be treated as empty string) Example 3: Input: "(()*" Output: True (The star will be treated as ')') Example 4: Input: "(*())" Output: True Example 5: Input: "(**))))" Output: false Note: The string size will be in the range [1, 100]. This problem is the day 16 challenge of LeetCode 30 day challenge. Website - https://webrewrite.com/ Paypal - https://www.paypal.me/programmingtutorials

Download

1 formats

Video Formats

360pmp420.1 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Valid Parenthesis String | LeetCode 678 | Programming Tutorials | NatokHD