java - Compare Multiple Substrings -
i'm attempting write basic dna sequencer. in that, given 2 sequences of same length, output strings same, minimal length of 3. input of
abcdef dfeabc   will return
1 abc   i not sure how go solving problem. can compare 2 strings, , see if equal. there, can compare length-1 string size, i.e. if dfeabc contains abcde. however, how can program possible strings, down minimal size of 3 characters? 1 issue above example of length-1, i'd have string bcdef , compare that. 
the naive way every single substring of string , see if it's in string b.
here's naive way of doing that:
for ( int = 0; < a.length; i++ ) {    ( int j = i+1; j <= a.length; j++ ) {        if (b.contains(a.substring(i, j))) {            //if longer last found match, record match        }    } }   the more optimal way @ longer substrings first, first substring matches longest.
for ( int length = a.length; length > 0; length-- ) {      ( int = 0; + length < a.length; i++ ) {          if ( b.contains(a.substring(i, i+length)) ) {              //this biggest match          }      } }      
Comments
Post a Comment