leetcode-1011. 在 D 天内送达包裹的能力
1011. 在 D 天内送达包裹的能力
123456789101112131415161718192021222324252627282930313233343536class Solution { public int shipWithinDays(int[] weights, int D) { return binarySearch(0, Integer.MAX_VALUE, weights, D); } public int binarySearch(int l, int r, int[] weights, int D){ while(l < r){ int mid = l + (r-l)/2; if(isValid(mid, weights, D)){ r = mid; }else{ l = mid + 1; ...
leetcode-897. 递增顺序搜索树
897. 递增顺序搜索树
1234567891011121314151617181920class Solution { TreeNode r = new TreeNode(); public TreeNode increasingBST(TreeNode root) { TreeNode res = r; dfs(root); return res.right; } public void dfs(TreeNode root){ if(root == null){ return; } dfs(root.left); TreeNode tmp = new TreeNode(root.val); r.right = tmp; r = tmp; dfs(root.right); }}
377. 组合总和 Ⅳ
377. 组合总和 Ⅳ
1234567891011121314151617181920212223class Solution { public int combinationSum4(int[] nums, int target) { int[] dp = new int[target+1]; // 初始化dp for(int num : nums){ if(num <= target){ dp[num] = 1; } } dp[0] = 1; for(int i = 1; i <= target; i++){ int count = 0; for(int num : nums){ if(i - num >=0 ){ ...
363. 矩形区域不超过 K 的最大数值和
363. 矩形区域不超过 K 的最大数值和
123456789101112131415161718192021222324252627282930313233class Solution { public int maxSumSubmatrix(int[][] matrix, int k) { int row = matrix.length; int columns = matrix[0].length; int[][] dp = new int[row+1][columns+1]; // 初始化dp dp[1][1] = matrix[0][0]; for (int i = 1; i <= row; i++) { for (int j = 1; j <= columns; j++) { int ans = 0; for (int l = 1; l <= i ...
leetcode-91. 解码方法
91. 解码方法
12345678910111213141516171819202122232425262728293031323334353637383940414243class Solution { public int numDecodings(String s) { int n = s.length(); int[] dp = new int[n + 1]; // 初始化dp if (s.startsWith("0")) { return 0; } else { dp[1] = 1; if (n == 1) { return dp[1]; } if (s.charAt(1) == '0') { if (Intege ...
leetcode-216.组合总和III
leetcode-216.组合总和III
1234567891011121314151617181920212223242526class Solution { List<List<Integer>> result = new ArrayList<>(); List<Integer> ans = new ArrayList<>(); public List<List<Integer>> combinationSum3(int k, int n) { int[] arr = new int[]{1,2,3,4,5,6,7,8,9}; dfs(arr, 0, k, n); return result; } public void dfs(int[] arr, int begin, int k, int n){ if (n == 0 && k == ...
leetcode-332.重新安排行程
leetcode-332.重新安排行程
原始思路 ---------------------------没做过–超时了,看完图再做!!!!!!!!!
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960class Solution { List<List<String>> result = new ArrayList<>(); List<String> tmp = new ArrayList<>(); //记录起始位置 List<String> strs = new ArrayList<>(); Set<String> set = new HashSet<>(); public List<String> findItinerary(List<List ...
leetcode-208. 实现 Trie (前缀树)
208. 实现 Trie (前缀树)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152class Trie { private Trie[] children; private boolean isEnd; /** Initialize your data structure here. */ public Trie() { children = new Trie[26]; isEnd = false; } /** Inserts a word into the trie. */ public void insert(String word) { Trie node = this; for (int i = 0; i < word.length(); i++) { ...
设计模式
设计模式
工厂方式模式:
抽象工厂模式:易于扩展,不符合开闭原则 AbstractFactoryBean
单例模式:
饿汉式
懒汉式
docker笔记
docker笔记