clueless coding // TODO: be smarter

LeetCode Strobogrammatic Number: CPP Solution



TL;DR Code Solution


bool isStrobogrammatic(string num) {

    unordered_map<char, char> map{
        {'0', '0'}, {'1', '1'}, {'6', '9'}, {'8', '8'}, {'9', '6'}
    };

    int i = 0;
    int j = num.length() - 1;

    while (i <= j) {

        if (map.find(num[i]) == map.end() || map.find(num[i]) == map.end() || map[num[i]] != num[j]) {
            return false;
        }

        i++; j--;
    }

    return true;

}