We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Nice idea. Thanks. It can be faster with standard search function like String.indexOf( String, int ), and some "break"s, when continuing loop is senseless:
String result = "NO";
out: for( int k = 0 ; k < R - r + 1 ; k++ ) {
int start = 0;
do {
start = G[k].indexOf( P[0], start );
if( start > -1 ) {
int count = 1;
for( int i = 1 ; i < r ; i++ ) {
if( G[k + i].
substring( start, start + c ).equals( P[i] ) )
count++;
else
break;
}
if( count == r ) {
result = "YES";
break out;
}
start++;
}
} while( start > -1 );
}
System.out.println( result );
The Grid Search
You are viewing a single comment's thread. Return to all comments →
Nice idea. Thanks. It can be faster with standard search function like String.indexOf( String, int ), and some "break"s, when continuing loop is senseless: