1、题目描述
2、代码
1 int rotatedDigits(int N) { 2 int res = 0; 3 4 for (int i = 1; i <= N; i++) { 5 if (isGood(i)) { 6 res++; 7 } 8 } 9 10 return res; 11 } 12 13 bool isGood(int x) 14 { 15 int rx = x; 16 vector<int> nums; 17 while (x) { 18 int r = x % 10; 19 nums.push_back(r); 20 x = x / 10; 21 } 22 23 for (vector<int>::iterator it = nums.begin(); it != nums.end(); it++ ) { 24 if (*it == 3 || *it == 4 || *it == 7) 25 return false; 26 if (*it == 0 || *it == 1 || *it == 8) 27 continue; 28 29 if (*it == 2) { 30 *it = 5; 31 continue; 32 } 33 34 if (*it == 5) { 35 *it = 2; 36 continue; 37 } 38 39 if (*it == 6) { 40 *it = 9; 41 continue; 42 } 43 44 if (*it == 9) { 45 *it = 6; 46 continue; 47 } 48 } 49 50 int good = 0; 51 for (vector<int>::reverse_iterator ite = nums.rbegin(); ite != nums.rend(); ite++) { 52 good = good * 10 + *ite; 53 } 54 55 return good != rx; 56 }