C solution (3ms)


  • 0
    bool valid(char left, char right) {
        if (left == '0' && right == '0' ||
            left == '1' && right == '1' ||
            left == '6' && right == '9' ||
            left == '8' && right == '8' ||
            left == '9' && right == '6') {
            return true;
        }
        return false;
    }
    
    bool isStrobogrammatic(char* num) {
        if (!num) return false;
        char *s = num, *e = num + strlen(num) - 1;
        while (s <= e) {
            if (!valid(*s++, *e--)) return false;
        }
        return true;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.