AP Computer Science Question: Does efficiency matter?

<p>For example, my solution for the 2008 4a is:</p>

<p>
[quote]

public class SubstringChecker implements Checker
{
String s1;</p>

<p>public SubstringChecker (String s)
{
s1 = s;
}</p>

<p>public boolean accept(String phrase)
{
boolean a1 = false;
int length = phrase.length();
for (int i = 0; i < (length - s1.length); i++)
{
if (phrase.substring(i, i+length)isEqualTo(s1))
{
a1 = true;
}
}
return a1;
}

[/quote]
</p>

<p>Whereas a solution online that makes MUCH more sense is:

[quote]

public class SubstringChecker implements Checker
{
private String substr;</p>

<p>public SubstringChecker(String s)
{
substr = s;
}</p>

<p>public boolean accept(String text)
{
return text.indexOf(substr) >= 0;
}
}

[/quote]
</p>

<p>Another example - my solution for 4b.

</p>

<p>and the nicer solution found online is:

</p>

<p>Nope. In act I did this problem for practice yesterday. And my teacher graded it. I got full points.</p>

<p>My code was the exact same as your minus the boolean. So efficiency doesn’t matter, unless you start re-writing code. That can get you penalized.</p>

<p>Just saves you time on the actual exam.</p>

<p>For 4a, can’t you just do</p>

<p>

or would that be not allowed because contains is not part of the Java subset?</p>

<p>^curious about that too, now that I know that such a thing exists (sorry for being complete noobsauce about programming… I’m more of a humanities guy). Seems like it’d be a huge time saver.</p>

<p>^^My teacher said that for-loops, contains, and indexOf are all valid.</p>

<p>You can use any code in the standard Java library, if I’m not wrong.
I doubt I stayed within the confines of the Java subset last year, since I didn’t know one existed. :P. (Most of my Java skills have come from random programming where I looked code up in the API and just wrote, rather than from in class).</p>

<p>Also, efficiency is definitely irrelevant. I wrote way more than necessary last year in order to circumvent some stuff that I couldn’t remember.</p>

<p>I was just doing that problem, and I have the canonical solutions - it specifically says that contains is allowed, so I wouldn’t worry.</p>

<p>And yes, efficiency doesn’t matter - I mean, you might save yourself some time, but it won’t be a problem.</p>