标签:its count ++ targe public dig class ref rem
题目:链接
1 class Solution { 2 private: 3 vector<vector<int>> rems; 4 public: 5 int countNumbersWithUniqueDigits(int n) 6 { 7 int sums = 0; 8 if(n == 0) 9 return 1; 10 vector<int> out; 11 for (int i = 1; i <= n; ++i) 12 backtracking(i, 0, out, sums); 13 return sums; 14 } 15 16 void backtracking(int n, int end, vector<int> &out, int &sums) 17 { 18 if (end == n) 19 { 20 sums++; 21 return; 22 } 23 if (end == 0 && n != 1) 24 { 25 for (int j = 1; j <= 9; ++j) 26 if (find(out.begin(), out.end(), j) != out.end()) 27 continue; 28 else 29 { 30 out.push_back(j); 31 backtracking(n, end + 1, out, sums); 32 out.pop_back(); 33 } 34 } 35 else 36 { 37 for (int j = 0; j <= 9; ++j) 38 if (find(out.begin(), out.end(), j) != out.end()) 39 continue; 40 else 41 { 42 out.push_back(j); 43 backtracking(n, end + 1, out, sums); 44 out.pop_back(); 45 } 46 } 47 } 48 };
【Leetcode】Count Numbers with Unique Digits(计算各个位数不同的数字个数)
标签:its count ++ targe public dig class ref rem
原文地址:https://www.cnblogs.com/sunbines/p/9330863.html