Pages

C++ Example

/**
 * Finds the first non-repeating character in a string.
 *
 * It is assumed that the string only consists of lower-case, English, characters.
 * This is a solution that only iterates the given string once, and uses O(1) additional
 * memory. The additional memory is O(1) because both the vector and map will hold a
 * maximum of 26 characters each. 
 *
 * @param s The string of characters to be analyzed.
 *
 * @returns The first non-repeated character, if found. Otherwise, '_'.
*/
char first_not_repeating_character(std::string s) {
    std::map<char, int> seen_chars;
    std::vector<char> order_seen;
    
    for (auto c: s) {        
        auto found = seen_chars.find(c);
        
        if (found != std::end(seen_chars)) {
            found->second += 1;
        } else {
            seen_chars[c] = 1;
            order_seen.push_back(c);
        }
    }
    
    for (auto c: order_seen)
        if (seen_chars[c] == 1) 
            return c;
    
    return '_';
}

1 comment:

  1. Compared to the cacophony of a on line casino flooring, Bally’s showroom was virtually monastic, the lights low and the room silent apart from the soothing hum of two dozen hibernating consoles. Once you could have} made your choices and the alternatives are revealed, all the opposite symbols may be be} revealed as well - typically with a greater possibility than the ones you picked. Nothing is ever "beneath" these symbols to pick from; the machine changes the icon picture to whatever its current calculation quantity tells it to reward you. Was it as a result of|as a result of} if a player were losing their cash too quickly - resulting in a shorter machine play time - the machine would "compensate" by paying out more earlier than the end of the taking part in} time? This time of 파라오카지노 play adjustment would then allow on line casino patrons, each on and offline, to "really feel" they'd value for cash {due to the|because of the|as a result of} adjusted extension of taking part in} time on the machine.

    ReplyDelete