Solved

parentbit challenge

Posted on 2016-09-21
3
50 Views
Last Modified: 2016-09-22
Hi,

I am going through below challenge

Recursion-1 > parenBit
prev  |  next  |  chance
Given a string that contains a single pair of parenthesis, compute recursively a new string made of only of the parenthesis and their contents, so "xyz(abc)123" yields "(abc)".

parenBit("xyz(abc)123") → "(abc)"
parenBit("x(hello)") → "(hello)"
parenBit("(xy)1") → "(xy)"
i have not understood the description. please advise
0
Comment
Question by:gudii9
  • 2
3 Comments
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> i have not understood the description.
What don't you understand?

Given a string containing '(' and ')', you have to strip off everything before the '(' and after the ')'.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
Comment Utility
Consider this:
public String parenBit(String str) {
  if (str.startsWith("(")) {
     return "(" + str.substring(1, str.indexOf(")")+1);
  }
  return parenBit(str.substring(1));
}

Open in new window

0
 
LVL 7

Author Comment

by:gudii9
Comment Utility
i missed the link

http://codingbat.com/prob/p137918


i understood the chalenge now
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now