Leetcode 246 Solution

This article provides solution to leetcode question 246 (strobogrammatic-number)

https://leetcode.com/problems/strobogrammatic-number

Solution

class Solution {
public:
    bool isStrobogrammatic(string num) {
        int l = 0;
        int r = num.size() - 1;

        while (l <= r)
        {
            if ((num[l] == '0' && num[r] == '0')
                || (num[l] == '1' && num[r] == '1')
                || (num[l] == '8' && num[r] == '8')
                || (num[l] == '6' && num[r] == '9')
                || (num[l] == '9' && num[r] == '6'))
                l++, r--;
            else
                return false;
        }

        return true;
    }
};