标签:
/* * 357. Count Numbers with Unique Digits * 2016-7-13 by Mingyang * 这个题目输出的结果的顺序是 * 0,1,10,12,13.。。。19 * 2,20,21,23.。。。29 * 3,30,31,32.。。39 * 利用if(visited[0] && index == 1) 来规避0开头的第二位数的情况 */ public int ress = 0; public int countNumbersWithUniqueDigits(int n) { if (n == 0) { return 1; } dfs(0, new boolean[10], n); return ress; } public void dfs(int index, boolean[] visited, int n) { if (index > 0) { ress++; } if (index == n) { return; } for (int i = 0; i <= 9; i++) { if (visited[0] && index == 1) { continue; } if (!visited[i]) { visited[i] = true; dfs(index + 1, visited, n); visited[i] = false; } } }
357. Count Numbers with Unique Digits
标签:
原文地址:http://www.cnblogs.com/zmyvszk/p/5670019.html