Delimiters
is #3 from the from the 2019 AP Computer Science A Free Response problems.
https://apcentral.collegeboard.org/pdf/ap19-frq-computer-science-a.pdf?course=ap-computer-science-a
Part (a) getDelimitersList
method
public ArrayList<String> getDelimitersList(String[] tokens)
{
ArrayList<String> delimiters = new ArrayList<String>();
for(String t : tokens)
if(t.equals(openDel) || t.equals(closeDel))
delimiters.add(t);
return delimiters;
}
Part (b) isBalanced
method
public boolean isBalanced(ArrayList<String> delimiters)
{
int numOpen = 0, numClosed = 0;
for(String d : delimiters)
{
if(d.equals(openDel))
numOpen++;
if(d.equals(closeDel))
numClosed++;
if(numClosed > numOpen)
return false;
}
return numOpen == numClosed;
}
2019 AP CS Exam Free Response Solutions
- APCalendar Free Response Solution
- StepTracker Free Response Solution
- LightBoard Free Response Solution
Additional ArrayList
resources
Help & comments
Get help from AP CS Tutor Brandon Horn