string - Longest substring of repeated characters -


i have assignment school in which, given input string of entirely 0's , 1's, must return length of longest substring of repeated 1's. not allowed use having trouble fleshing out idea. far have found length of input string , converted input string uint8. way can use find find indices of ones. next thought sort of loop store indices, or maybe check length of each subset , save longest one? i'm not sure how go part or if right way think it. guidance appreciated.

you can use regular expressions this:

[s,e] = regexp(inputstring,'(1+)'); maximumsequencelength = max(e-s+1); 

if want find longest substring of character, use following dynamic regular expression, says: "take character. match many of character possible"

   [s,e] = regexp(inputstring,'(.)((??$1*))'); 

inputstring(s) returns first element of each substring.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -