摘要: java第四章 1. 运算符 短路与的判断方式是: 从左到右依次判断,直到出现false为止将不再判断,直接得到结果为false(短路遇false就停) **逻辑或和短路或的区别 逻辑或的判断方式是:**从左到右依次判断,直到结尾 阅读全文
posted @ 2020-12-27 22:16 alexemey 阅读(46) 评论(0) 推荐(0)
摘要: java第三章 1. 标识符命名规范 2. 变量定义 3. 变量类型 4. 类型转换 强制转化 package com.example.helloworld; public class HelloWorld { public static void main(String[] args) { dou 阅读全文
posted @ 2020-12-27 22:14 alexemey 阅读(43) 评论(0) 推荐(0)
摘要: Leetcode Acwing 动态规划 \(O(n^2)\) 设f[i]为有1~i结点的二叉搜索数方案的数量。我们将问题看作两个子问题:根节点的左子树有几个结点?它们的方案数是多少?根节点的右子树有几个结点?它们的方案数是多少?枚举这些情况,f[i]就是这些情况的和。 \[ f(i,j) = \S 阅读全文
posted @ 2020-12-27 20:20 alexemey 阅读(45) 评论(0) 推荐(0)
摘要: 对应acwing,其实应该叫最短编辑距离 Leetcode Acwing 动态规划 \(O(n^2)\) 时间复杂度 \(O(n^2)\) 空间复杂度 \(O(n^2)\) C++ 代码 class Solution { public: int minDistance(string word1, s 阅读全文
posted @ 2020-12-27 19:33 alexemey 阅读(59) 评论(0) 推荐(0)
摘要: leetcode acwing 动态规划 \(O(n)\) 设从第1级台阶走到第i级台阶所需要的步数是f[i],由于只能走1步或者2步。我们假设到第i级台阶的最后一步有两种情况:走了1步和走了2步。因此我们得到状态转移方程是 \[ f[i] = f[i-1] + f[i-2] \] 时间复杂度 \( 阅读全文
posted @ 2020-12-27 18:14 alexemey 阅读(71) 评论(0) 推荐(0)
摘要: Leetcode Acwing 动态规划 \(O(n^2)\) 和LeetCode 62. 不同路径思路相似。 时间复杂度 \(o(n^2)\) 空间复杂度 \(O(n^2)\) C++ 代码 class Solution { public: int minPathSum(vector<vector 阅读全文
posted @ 2020-12-27 18:01 alexemey 阅读(69) 评论(0) 推荐(0)
摘要: leetcode acwing 动态规划 \(O(n)\) 设定f[i,j]为从起点到店[i,j]的路径数量,由于机器人只会向下或者向右,所以状态转移关系式很容易求得 \[ f[i,j] = f[i-1,j] + f[i,j-1] \] 时间复杂度 \(O(n^2)\) 空间复杂度 \(O(n^2) 阅读全文
posted @ 2020-12-27 17:42 alexemey 阅读(54) 评论(0) 推荐(0)
摘要: LeetCode 53. 最大子序和 LeetCode Acwing (动态规划)\(O(n)\) 时间复杂度 \(O(n)\) 空间复杂度 \(O(n)\) class Solution { public: int maxSubArray(vector<int>& nums) { int n = 阅读全文
posted @ 2020-12-26 00:34 alexemey 阅读(36) 评论(0) 推荐(0)
摘要: LeetCode 44. 通配符匹配 LeetCode Acwing (动态规划)\(O(n)\) 本题的解题思路和10. 正则表达式匹配是一样的。但是要注意,这里的*是通配符,它可以匹配长度从0至任意长的任意字符串。 时间复杂度 \(O(n)\) 空间复杂度 \(O(n)\) class Solu 阅读全文
posted @ 2020-12-26 00:07 alexemey 阅读(58) 评论(0) 推荐(0)
摘要: leetcode acwing 题解 算法1 两遍线性扫描+贪心$O(n)$ 线性扫描一遍字符串,设置sum = 0,假如是(,就+1,假如是),就-1;计算完之后判断一下当前的和,如果sum == 0说明是有效字符串,统计一下结果。如果是sum < 0说明)太多了,这种情况无论我们输入什么都没法形 阅读全文
posted @ 2020-12-24 17:11 alexemey 阅读(93) 评论(0) 推荐(0)