From c234b17a7182e10b1bdd97ca1e0e0a627e4aa625 Mon Sep 17 00:00:00 2001 From: "huangge1199@hotmail.com" Date: Sun, 1 Aug 2021 13:53:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=20252=20=E5=9C=BA=E5=91=A8=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/code/leet/doubleWeek/SolutionD58.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/main/java/com/code/leet/doubleWeek/SolutionD58.java diff --git a/src/main/java/com/code/leet/doubleWeek/SolutionD58.java b/src/main/java/com/code/leet/doubleWeek/SolutionD58.java new file mode 100644 index 0000000..bb989e7 --- /dev/null +++ b/src/main/java/com/code/leet/doubleWeek/SolutionD58.java @@ -0,0 +1,74 @@ +package com.code.leet.doubleWeek; + +public class SolutionD58 { + public static void main(String[] args) { + SolutionD58 solution = new SolutionD58(); +// System.out.println(solution.minimumPerimeter(1000000000)); + System.out.println(solution.countSpecialSubsequences(new int[]{0, 1, 2, 0, 1, 2})); + } + + + public boolean isThree(int n) { + int flag = 0; + if (n <= 2) { + return false; + } + int num = n / 2; + for (int i = 3; i < num; i++) { + if (n % i == 0) { + if (flag == 1) { + return false; + } + flag = 1; + } + } + return flag == 1; + } + + public long numberOfWeeks(int[] milestones) { + long max = 0; + long sum = 0; + for (int milestone : milestones) { + sum += milestone; + max = Math.max(max, milestone); + } + return sum / max >= 2 ? sum : (sum - max) * 2 + 1; + } + + public long minimumPerimeter(long neededApples) { + if (neededApples == 0) { + return 0; + } + if (neededApples < 12) { + return 8; + } + long n = 2; + long cur = 12; + long sum = 12; + while (sum < neededApples) { + cur = cur + 12 * (n + 1); + sum += cur; + n += 2; + } + return 4 * n; + } + + public int countSpecialSubsequences(int[] nums) { + long[] result = new long[3]; + long[] counts = new long[nums.length]; + for (int i = nums.length - 1; i >= 0; i--) { + int num = nums[i]; + if (num == 1) { + counts[i] = result[2]; + result[num] += counts[i]; + } else if (num == 0) { + result[num] = result[1] * result[2]; + } else { + + } + } +// return (int) (result[0][2] % 100000007); + return 0; + } + +}