摘要:法1:O(n) 要改变数组,partition的思想 1 class Solution { 2 public int[] getLeastNumbers(int[] arr, int k) { 3 int[] ans = new int[k]; 4 findKMin(arr,0,arr.length
阅读全文
摘要:990. 等式方程的可满足性 1 class Solution { 2 public boolean equationsPossible(String[] equations) { 3 int[] parent = new int[26];//存放节点的父节点 4 for(int i = 0; i
阅读全文
摘要:回溯法的解体框架 解决一个回溯问题,实际上就是一个决策树的遍历过程。一般来说,我们需要解决三个问题: 路径:也就是已经做出的选择。选择列表:也就是你当前可以做的选择。结束条件:也就是到达决策树底层,无法再做选择的条件。 可以套用模板: LinkedList result = new LinkedLi
阅读全文
摘要:暴力解法一:枚举宽度 1 class Solution { 2 public int largestRectangleArea(int[] heights) { 3 int n = heights.length; 4 int ans = 0; 5 // 枚举左边界 6 for (int left =
阅读全文