From the course: Nail Your Java Interview
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Solution: Matching parentheses - Java Tutorial
From the course: Nail Your Java Interview
Solution: Matching parentheses
(upbeat music) - [Instructor] Let's create a function that can determine if a piece of text has matching parentheses. As always, the first step is to set up some tester input. We'll use them in our matching parentheses function and see whether or not each string has matching parentheses. Through a visual check, we can see that the first four strings have matching parentheses, or matching block symbols, and the last four strings do not have matching parentheses. Let's take a look at our function. It's called matchingParentheses and it takes in a string as input. It returns a Boolean that represents whether or not the input string has matching parentheses. To start off, we create some data structures. The stack will help us keep track of the parentheses symbols as we iterate throughout the string. The map gives us a correspondence between a given open symbol and a closed symbol, since a square bracket cannot close an…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Leveraging stacks as a data structure4m 36s
-
(Locked)
Using queues in technical interviews4m 5s
-
(Locked)
Mastering hash-based structures4m 51s
-
(Locked)
Challenge: Generate binary numbers1m 19s
-
(Locked)
Solution: Generate binary numbers6m 35s
-
(Locked)
Challenge: Matching parentheses1m 5s
-
(Locked)
Solution: Matching parentheses3m 51s
-
(Locked)
Challenge: Find most repeated word2m 16s
-
(Locked)
Solution: Find most repeated word3m 28s
-
-
-