문제 소개Medium / Binary Searchhttps://leetcode.com/problems/capacity-to-ship-packages-within-d-days/description/풀이public int shipWithinDays(int[] weights, int days) { int answer = 0; int left = 0, right = 0; for (int tmp : weights) { left = Math.max(left, tmp); right += tmp; } while (left mid) { day++; result = 0; } r..
문제 소개Medium / Dynamic Programminghttps://leetcode.com/problems/count-sorted-vowel-strings/description/풀이public int countVowelStrings(int n) { int[] dp = new int[]{1, 1, 1, 1, 1}; while (--n > 0) { for (int i = 3; i >= 0; i--) { // 각 인덱스 a, e, i, o 에 대한 개수를 할당함 dp[i] += dp[i + 1]; // a는 나머지 4개를 포함한 경우의 수, e는 나머지 3개를 포함한 경우의 수, i 는 나머지 2개, o는 나머지 1개, u는 제외 / u는 항상 1개 => 모두 ..
문제 소개Medium / Dynamic Programminghttps://leetcode.com/problems/all-possible-full-binary-trees/description/풀이public List allPossibleFBT(int n) { if (n%2 == 0) { return new ArrayList(); } List result = new ArrayList(); if (n == 1) { result.add(new TreeNode(0)); } else { for (int leftNodes = 1; leftNodes 이번 문제는 DFS로 풀어내야겠다는 생각은 들었지만, 그 이상으로 접근하기가 어려웠다.그렇기에 내용을 풀어..