随笔分类 - leetcode
摘要:java 解法 阶梯形式 动态规划保存 每个位置取上面 或者斜上面的数 重叠则需要把小的保存到flag 中 然后到最后一层则直接看那个数最小 则为最小路径 class Solution { //消耗的空间过大 public int minimumTotal(List triangle) { int
阅读全文
摘要:Python class Solution: def maxSubArray(self, nums: List[int]) int: max = nums[0] sum = nums[0] for i in range(1,len(nums)): if sum =0: sum = sum + num
阅读全文
摘要:boolean[] a1 = new boolean[5]; Arrays.fill( a1,true ); 结果 a1[] = {true,true,true,true,true}; 用法2:接受4个参数 例如: String[] a9 = new String[6]; Arrays.fill(a
阅读全文
摘要:class Solution { HashMap hm; HashSet ls; public List findRepeatedDnaSequences(String s) { hm = new HashMap(); ls = new HashSet(); for (int i = 0; i
阅读全文
摘要:https://www.acwing.com/solution/LeetCode/content/3785/ class Solution { private boolean flag; public boolean makesquare(int[] nums) { int temp = 0; fo
阅读全文
摘要:1. 步骤1 :将所有的值保存到 列 行 3 3矩阵中 2. 步骤2 : 1~9 判断那个值可以选 可以选代入 然后回复现场 class Solution { boolean col[][]; boolean row[][]; boolean cell[][][]; public void solv
阅读全文
摘要: ``` class Solution { int count; List ls; int n; boolean bool[][]; public List> solveNQueens(int n) { count
阅读全文
摘要: ``` class Solution { private List ls; private int n; private LinkedList path; private int k; private int[]
阅读全文
摘要:class Solution { private List ls; private int n; private LinkedList path; public List subsetsWithDup(int[] nums) { ls = new LinkedList (); path = new
阅读全文
摘要:递归 class Solution { private List ls; private boolean []bool; private int n; public List subsets(int[] nums) { n = nums.length; ls = new LinkedList();
阅读全文
摘要: ``` class Solution { private int n; private List ls; private boolean[] bool; private LinkedList path; publi
阅读全文
摘要:class Solution { private LinkedList ans = new LinkedList(); private int n; private LinkedList path = new LinkedList(); private boolean[] bool; public
阅读全文
摘要:class Solution { int n; int m; int dx[] = new int[] { 1, 0, 1, 0 }; int dy[] = new int[] { 0, 1, 0, 1 }; public boolean exist(char[][] board, String w
阅读全文
摘要:递归 class Solution { List ls; String[] arr = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" }; public List letterCombinations(Strin
阅读全文
摘要:java与c++不同,java只存在值传递,不存在引用传递,不存在指针,所以,完全照搬c++用指针的方式(剑指offer第37题)来做是不行的,需要做变通。所以,在此我尝试用StringBuilder(不能直接用String,因为String是不可变对象,是被final修饰的,每次对String修改
阅读全文
摘要:通过一个优先队列进行存储数据 然后每一次读数据都是输出第一个结点 中序遍历+栈模拟
阅读全文
摘要:最大的直径可能有三种情况: 1.在左子树内部 2.在右子树内部 3.在穿过左子树,根节点,右子树的一条路径中 设计一个递归函数,返回以该节点为根节点,向下走的最长路径 知道这个值以后 以某个节点为根节点的最长直径就是,该节点左子树向下走的最长路径 ,再加上该节点右子树向下走的最长路径 我们用一个全局
阅读全文
摘要:
 ```
class Sol...
阅读全文
摘要:因为是二叉搜索树 所以左边小 右边大 递归 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { int pval = p.val; int qval = q.va
阅读全文
摘要:  ``` class Sol...
阅读全文

浙公网安备 33010602011771号