Fork me on GitHub

随笔分类 -  leetcode

摘要:java 解法 阶梯形式 动态规划保存 每个位置取上面 或者斜上面的数 重叠则需要把小的保存到flag 中 然后到最后一层则直接看那个数最小 则为最小路径 class Solution { //消耗的空间过大 public int minimumTotal(List triangle) { int 阅读全文
posted @ 2019-09-05 09:32 cznczai 阅读(188) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-09-04 11:55 cznczai 阅读(145) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-08-28 15:10 cznczai 阅读(98) 评论(0) 推荐(0)
摘要:class Solution { HashMap hm; HashSet ls; public List findRepeatedDnaSequences(String s) { hm = new HashMap(); ls = new HashSet(); for (int i = 0; i 阅读全文
posted @ 2019-08-27 17:07 cznczai 阅读(101) 评论(0) 推荐(0)
摘要:https://www.acwing.com/solution/LeetCode/content/3785/ class Solution { private boolean flag; public boolean makesquare(int[] nums) { int temp = 0; fo 阅读全文
posted @ 2019-08-24 16:19 cznczai 阅读(128) 评论(0) 推荐(0)
摘要:1. 步骤1 :将所有的值保存到 列 行 3 3矩阵中 2. 步骤2 : 1~9 判断那个值可以选 可以选代入 然后回复现场 class Solution { boolean col[][]; boolean row[][]; boolean cell[][][]; public void solv 阅读全文
posted @ 2019-08-24 13:44 cznczai 阅读(156) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190823151254751-218061603.png) ``` class Solution { int count; List ls; int n; boolean bool[][]; public List> solveNQueens(int n) { count 阅读全文
posted @ 2019-08-23 15:13 cznczai 阅读(133) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190822141707476-1324418788.png) ``` class Solution { private List ls; private int n; private LinkedList path; private int k; private int[] 阅读全文
posted @ 2019-08-22 14:17 cznczai 阅读(84) 评论(0) 推荐(0)
摘要:class Solution { private List ls; private int n; private LinkedList path; public List subsetsWithDup(int[] nums) { ls = new LinkedList (); path = new 阅读全文
posted @ 2019-08-22 13:16 cznczai 阅读(68) 评论(0) 推荐(0)
摘要:递归 class Solution { private List ls; private boolean []bool; private int n; public List subsets(int[] nums) { n = nums.length; ls = new LinkedList(); 阅读全文
posted @ 2019-08-21 12:53 cznczai 阅读(101) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190820133550003-614844358.png) ``` class Solution { private int n; private List ls; private boolean[] bool; private LinkedList path; publi 阅读全文
posted @ 2019-08-20 13:39 cznczai 阅读(99) 评论(0) 推荐(0)
摘要:class Solution { private LinkedList ans = new LinkedList(); private int n; private LinkedList path = new LinkedList(); private boolean[] bool; public 阅读全文
posted @ 2019-08-19 13:31 cznczai 阅读(107) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-08-18 13:03 cznczai 阅读(154) 评论(0) 推荐(0)
摘要:递归 class Solution { List ls; String[] arr = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" }; public List letterCombinations(Strin 阅读全文
posted @ 2019-08-17 10:20 cznczai 阅读(224) 评论(0) 推荐(0)
摘要:java与c++不同,java只存在值传递,不存在引用传递,不存在指针,所以,完全照搬c++用指针的方式(剑指offer第37题)来做是不行的,需要做变通。所以,在此我尝试用StringBuilder(不能直接用String,因为String是不可变对象,是被final修饰的,每次对String修改 阅读全文
posted @ 2019-08-16 15:46 cznczai 阅读(157) 评论(0) 推荐(0)
摘要:通过一个优先队列进行存储数据 然后每一次读数据都是输出第一个结点 中序遍历+栈模拟 阅读全文
posted @ 2019-08-16 12:38 cznczai 阅读(110) 评论(0) 推荐(0)
摘要:最大的直径可能有三种情况: 1.在左子树内部 2.在右子树内部 3.在穿过左子树,根节点,右子树的一条路径中 设计一个递归函数,返回以该节点为根节点,向下走的最长路径 知道这个值以后 以某个节点为根节点的最长直径就是,该节点左子树向下走的最长路径 ,再加上该节点右子树向下走的最长路径 我们用一个全局 阅读全文
posted @ 2019-08-14 16:11 cznczai 阅读(160) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190814153445372-367844473.png) ![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190814153623593-404672251.png) ``` class Sol... 阅读全文
posted @ 2019-08-14 15:37 cznczai 阅读(92) 评论(0) 推荐(0)
摘要:因为是二叉搜索树 所以左边小 右边大 递归 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { int pval = p.val; int qval = q.va 阅读全文
posted @ 2019-08-14 15:05 cznczai 阅读(114) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190814125838838-227108132.png) ![](https://img2018.cnblogs.com/blog/1648545/201908/1648545-20190814123815095-274125627.png) ``` class Sol... 阅读全文
posted @ 2019-08-14 12:59 cznczai 阅读(101) 评论(0) 推荐(0)