Advertisement
nikunjsoni

246

Jun 22nd, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool isStrobogrammatic(string num) {
  4.         unordered_map<int, int> m;
  5.         int n = num.size();
  6.         m[1] = 1; m[0] = 0, m[6] = 9, m[8] = 8, m[9] = 6;
  7.  
  8.         for(int i=0, j=n-1; i<=j; i++, j--){
  9.             int d = num[i]-'0';
  10.             int d1 = num[j]-'0';
  11.             if(!m.count(d) || m[d] != d1) return false;
  12.         }
  13.         return true;
  14.     }
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement