Tuesday, November 20, 2012

Find non-unique characters in a given string

Optimal complexity in time and space

1 comment:

  1. std::set< char > output;
    sort( str.begin, str.end() );
    char prev = str[0];
    for ( int idx = 1; idx < str.length(); ++idx) {
    if ( str[idx] == prev ) output.insert(str[idx]);
    prev = str[idx];
    }

    result is in "output"

    ReplyDelete