Saturday, December 15, 2012

SRM 563 div 2 250-pt

Problem
http://community.topcoder.com/stat?c=problem_statement&pm=12334

Approach
Check if T contains S. If so, remove it, and see if they're equal. I realized i couldn't just do a straight replace, because it would replace all occurrences. So i went to look at the documentation and discovered the replaceFirst method. This is exactly what I needed.

Code 

public class FoxAndHandleEasy
{
public String isPossible(String S, String T)
{
if (T.replaceFirst(S, "").equals(S))
return "Yes";
else
return "No";
}
}

No comments:

Post a Comment

There was an error in this gadget