246. Strobogrammatic Number - cocoder39/coco39_LC GitHub Wiki

246. Strobogrammatic Number

while (start <= end) to process input like "6"; start < end is not good here

bool isStrobogrammatic(string num) {
        unordered_map<char, char> map{{'0', '0'}, {'1', '1'}, {'6', '9'}, {'8', '8'}, {'9', '6'}};
        
        int start = 0, end = num.length() - 1;
        while (start <= end) {
            if (map.find(num[start]) == map.end() || map[num[start]] != num[end] || map.find(num[end]) == map.end() || map[num[end]] != num[start]) {
                return false;
            }
            start++;
            end--;
        }
        return true;
    }
⚠️ **GitHub.com Fallback** ⚠️