GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Leetcode-Java/leetcode/solution/src/BeautifulArrangement.java at master · Tulpen/Leetcode-Java Expand file tree/ Copy pathBeautifulArrangement.javaMore file actions 26 lines (23 loc) · 658 Bytes / Copy pathBeautifulArrangement.javaFile metadata and controls26 lines (23 loc) · 658 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 /** * https://leetcode.com/articles/beautiful-arrangement/ */ public class BeautifulArrangement { public int countArrangement(int N) { int[] count = new int[1]; helper(N, 1, new boolean[N + 1], count); return count[0]; } private void helper(int N, int k, boolean[] visited, int[] count) { if (k > N) { count[0]++; return; } for (int i = 1; i <= N; i++) { if (!visited[i] && (i % k == 0 || k % i == 0)) { visited[i] = true; helper(N, k + 1, visited, count); visited[i] = false; } } } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |