1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marina86 [1]
3 years ago
12

Suppose you are given a string containing only the characters ( and ). In this problem, you will write a function to determine w

hether the string has balanced parentheses. Your algorithm should use no more than O (1) space beyond the input; any algorithms that use space not in O (1) will receive half credit at most. Any solutions that always return true (or always return false) or otherwise try to game the distribution of test cases will receive zero credit.
Balanced parentheses means that every open parenthesis has exactly one close parenthesis corresponding to it and vice versa, and that for each pair the opening parenthesis precedes the closed parenthesis. The following strings have balanced parentheses: () (()()) ((())())
The following strings do not have balanced parentheses: )( (() ())(()))())
We consider the empty string to have balanced parentheses, as there is no imbalance. Your program should accept as input a single string containing only the characters ) and (, and output a single line stating true or false.

Your task is to complete the hasBalancedParentheses() method.
Computers and Technology
1 answer:
Whitepunk [10]3 years ago
8 0

Answer:

Code is completed below

Explanation:

Source Code in Java:

class Parenthesis

{

boolean hasBalancedParentheses(String eq) //method to check and return if a set of parenthesis is balanced or not

{

int count=0; //to store count of current unclosed opening brackets

for(int i=0;i<eq.length();i++)

{

if(eq.charAt(i)=='(')

count++;

else if(eq.charAt(i)==')')

count--;

if(count<0) //if count falls below zero, there were more closing brackets than opening brackets till this point

return false;

}

if(count>0) //if count is still more than zero, there were less closing brackets than opening brackets

return false;

return true; //if program reaches this point, it has passed all the tests

}

public static void main(String args[])

{

//testing the function

Parenthesis ob=new Parenthesis();

System.out.println(ob.hasBalancedParentheses("()(()())((())())"));

System.out.println(ob.hasBalancedParentheses(")((()())(()))())"));

}

}

You might be interested in
Which attribute defines the file name for the specific image in an image tag??
serg [7]
Src="/absolute/or/relative/path/to/image.file"
6 0
3 years ago
The Earth's _______ is ductile overall, tending to flow very slowly and deform in a _______ manner.
kipiarov [429]

<span>The asthenosphere is a part of the upper mantle just below the </span>lithosphere<span> <span>that is involved in </span></span>plate tectonic movement<span> <span>and </span></span>isostatic<span> <span>adjustments. The lithosphere-asthenosphere boundary is conventionally taken at the 1300 °C </span></span>isotherm<span>, above which the mantle behaves in a rigid fashion and below which it behaves in a </span>ductile<span> fashion. a</span><span>nd </span>flows very slowly, in a manner<span> similar to the ice at a bottom of a glacier.</span>

5 0
3 years ago
Read 2 more answers
Which role is delegated to personnel of the IT department and is responsible for maintaining the integrity and security of the d
enyata [817]

Correct question.

Which role is delegated to personnel of the IT department and how is responsible for maintaining the integrity and security of the data?

Answer:

<u>data custodian</u>

<u>Explanation:</u>

Remember, every organization generates data, and large organizations generate even larger data.

Hence, the role of a data custodian in an organization requires He implements measures to protect the organization's data, store and backup the data, as well as granting access to the data to authorized persons when needed.

3 0
2 years ago
Networking Gadgets, Inc. currently employs eight people but plans to hire 10 more in the next four months. Users will work on mu
grandymaker [24]

Answer: Server based network

Explanation:

 The server based network is the type of network in which the special type of computer mainly handle the various networking tasks like the storing file, managing printers and authenticate the users in the system. The server based network are also responsible for run various types of application like the email and the database system.

The microsoft windows 2016 and the window 2012 are the two ideal OS (Operating system) that mainly used in the server based network.

Therefore, we use the server based network as it easy to backup and manage in the networking system.

3 0
3 years ago
A test's directions often clarify any questions a student might have about answering a response question.
alina1380 [7]
True, hope you have Have a good day
8 0
3 years ago
Read 2 more answers
Other questions:
  • A password checking system that disallows user passwords that are proper names or words that are normally included in a dictiona
    15·1 answer
  • Behaving in an acceptable manner within a workplace environment is referred to as having
    9·1 answer
  • Which of the following is not a metamorphic agent?
    8·2 answers
  • You view a portion of a document on the screen through a
    14·1 answer
  • Which of the following is a programming language that permits Web site designers to run applications on the user's computer?
    15·1 answer
  • Universal Containers uses a custom object within the product development team. Product development, executives, and System Admin
    11·1 answer
  • What are your considerations in making a derivative ict content ti effectively communicate or present data or information?
    11·1 answer
  • 5. The command to add new layout to the slide is present in<br>tab.​
    15·1 answer
  • An animation of a person standing with their arms extended out to their sides. There are 3 dimensional boxes around the torso of
    5·1 answer
  • The part of the computer that provides access to the internet is the
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!