• 【算法】和


    1、
    前缀和 算法不懂看这个链接 https://mp.weixin.qq.com/s?__biz=Mzg3Mzc0NjUzMQ==&mid=2247497090&idx=1&sn=417f4d570deb4d116dabb9a473ebdf7a&source=41#wechat_redirect
    单调栈 算法不懂看这个链接 https://mp.weixin.qq.com/s?__biz=Mzg3Mzc0NjUzMQ==&mid=2247497088&idx=1&sn=35e4f21d431d3c6ff91c2d6b62451339&source=41#wechat_redirect
    滑动窗口 算法不懂看这个链接 https://www.cnblogs.com/huansky/p/13488234.html
    双指针 算法不懂看这个链接 https://mp.weixin.qq.com/s?__biz=Mzg3Mzc0NjUzMQ==&mid=2247497066&idx=1&sn=1b62c9b5305576a06208b1a2202c9ea7&source=41#wechat_redirect
    二分 https://leetcode.cn/leetbook/read/binary-search/x6q6fi/

    BFS 算法不懂看这个链接 添加链接描述
    DFS 算法不懂看这个链接 https://www.bilibili.com/video/BV1P5411N7Xc

    设计题:
    1845. 座位预约管理系统 https://leetcode.cn/problems/seat-reservation-manager/
    1603. 设计停车系统 https://leetcode.cn/problems/design-parking-system/
    1846. 简易银行系统 https://leetcode.cn/problems/simple-bank-system/
    1797. 设计一个验证系统 https://leetcode.cn/problems/design-authentication-manager/
    面试题 03.06. 动物收容所 https://leetcode.cn/problems/animal-shelter-lcci/
    355. 设计推特 https://leetcode.cn/problems/design-twitter/
    1396. 设计地铁系统 https://leetcode.cn/problems/design-underground-system/

    字符串、排序
    http://oj.rnd.huawei.com/problems/374/submissions
    http://oj.rnd.huawei.com/problems/1904/details
    https://leetcode-cn.com/problems/bianry-number-to-string-lcci/
    https://leetcode-cn.com/problems/longest-palindromic-substring/
    https://leetcode-cn.com/problems/restore-ip-addresses/
    https://leetcode-cn.com/problems/basic-calculator-ii/

    链表、队列、哈希
    http://oj.rnd.huawei.com/problems/395/details
    http://oj.rnd.huawei.com/problems/282/details
    https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof/
    https://leetcode-cn.com/problems/top-k-frequent-words/
    https://leetcode-cn.com/problems/find-the-most-competitive-subsequence/
    https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/

    栈、单调栈
    https://leetcode-cn.com/problems/decode-string/
    https://leetcode-cn.com/problems/daily-temperatures/solution/
    https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters/
    https://leetcode-cn.com/problems/number-of-islands/
    https://leetcode-cn.com/problems/redundant-connection/
    https://leetcode-cn.com/problems/minimum-size-subarray-sum/

    递归
    https://leetcode-cn.com/problems/swap-nodes-in-pairs/
    https://leetcode-cn.com/problems/binary-tree-preorder-traversal/
    https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/
    https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
    https://leetcode-cn.com/problems/longest-substring-with-at-least-k-repeating-characters/
    https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets/

    树、二叉树
    https://leetcode-cn.com/problems/maximum-width-of-binary-tree/
    https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/
    https://leetcode-cn.com/problems/binary-tree-level-order-traversal/
    https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor/
    https://oj.rnd.huawei.com/problems/326/details
    https://oj.rnd.huawei.com/problems/216/details

    BFS、DFS:
    https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list/solution/
    https://leetcode-cn.com/problems/course-schedule/solution/
    https://leetcode-cn.com/problems/perfect-squares/
    https://leetcode-cn.com/problems/course-schedule/
    https://oj.rnd.huawei.com/problems/387/details
    https://oj.rnd.huawei.com/problems/1905/details

    贪心和动态规划:
    https://oj.rnd.huawei.com/problems/290/details
    https://leetcode-cn.com/problems/task-scheduler/
    https://leetcode-cn.com/problems/house-robber/
    https://leetcode-cn.com/problems/boats-to-save-people/
    https://leetcode-cn.com/problems/house-robber-iii/
    http://oj.rnd.huawei.com/problems/221/details


    2、
    leetcode插件设置:
    CodeFileName:自动生成类的类名。

    P$!{question.frontendQuestionId}_$!velocityTool.camelCaseName(${question.titleSlug})
    
    • 1
    ${question.content}
    package leetcode.editor.cn;
    
    /**
     * ${question.title}
     * @date $!velocityTool.date()
     */
    public class P${question.frontendQuestionId}_$!velocityTool.camelCaseName(${question.titleSlug}){
    	 public static void main(String[] args) {
    	 	 Solution solution = new P$!{question.frontendQuestionId}_$!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
    	 }
    
    ${question.code}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    在这里插入图片描述

    ${question.title}	题目标题	示例:两数之和
    ${question.titleSlug}	题目标记	示例:two-sum
    ${question.frontendQuestionId}	题目编号
    ${question.content}	题目描述
    ${question.code}	题目代码
    $!velocityTool.camelCaseName(str)	转换字符为大驼峰样式(开头字母大写)
    $!velocityTool.smallCamelCaseName(str)	转换字符为小驼峰样式(开头字母小写)
    $!velocityTool.snakeCaseName(str)	转换字符为蛇形样式
    $!velocityTool.leftPadZeros(str,n)	在字符串的左边填充0,使字符串的长度至少为n
    $!velocityTool.date()	获取当前时间
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    3、
    刷题刷题刷题。。。。目前在按Tag刷题,希望总结出套路和框架,在这里做一个整理。

    二分查找 Binary Search
    特征:有序数组查找元素,要求时间复杂度O(logN)。
    注意mid取值,向下取整 mid = (left + right) / 2 保证定位到左侧元素,向上取整 mid = (left + mid + 1) / 2定位右侧元素,防止左边界分支不变。
    35. 搜索插入位置

    1. 在排序数组中查找元素的第一个和最后一个位置

    2. 寻找两个正序数组的中位数

    回溯法 Backtracking
    题目特征:遍历,找出所有可能的组合;分步,每一步有不同选择。
    回溯意义:对所有节点进行尝试,添加当前节点到路径中,当前节点处理完成后,删除当前节点,返回上一步状态。
    深度优先遍历(Depth-First-Search,DFS):尽可能深地搜索,遍历。
    方法要点:结束条件、遍历、剪枝、选择路径、递归、删除路径。
    练手题目:
    46. 全排列

    1. 组合总和

    2. 复原 IP 地址

    3. 组合总和 II

    哈希表 Hash Table
    特征:搜索
    41. 缺失的第一个正数


    4、
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    中心主题
    递归
    题目
    509. 斐波那契数
    剑指 Offer 10- II. 青蛙跳台阶问题
    70. 爬楼梯
    时间复杂度: O(2^n),存在重复计算,需要缓存结果
    HashMap map = new HashMap<>();
    if (map.containsKey(n))
    map.get(n);
    226. 翻转二叉树
    112. 路径总和
    特判
    面试题 08.06. 汉诺塔问题
    构造递归函数
    注意移动盘个数
    细胞分裂
    注意题述,多个状态互相调用
    public static int cellSparete(int n) {
    return cellA(n) + cellB(n) + cellC(n);
    }

    public static int cellA(int n) {
        // 停止条件
        if (n == 0 || n == 1) {
            return 1;
        }
        // 递归
        return cellA(n - 1) + cellB(n - 1) + cellC(n - 1);
    }
    
    public static int cellB(int n) {
        // 注意b状态的停止条件最早为第1h
        if (n == 1) {
            return 1;
        }
        return cellA(n - 1);
    }
    
    public static int cellC(int n) {
        if (n == 0 || n == 1) {
            return 0;
        }
        if (n == 2) {
            return 1;
        }
        return cellB(n - 1);
    }
    		练习
    			21. 合并两个有序链表
    			24. 两两交换链表中的节点
    				ListNode.next
    			437. 路径总和 III
    	规律
    		问题可以分解成相同解决思路的子问题
    		可以调用同一个函数求解
    		分析问题从上到下,求解问题自下而上
    	解法
    		1、明确函数功能
    			根据输入输出写出函数作用
    		2、确定结束条件
    			问题不能继续分解,返回最小求解结果
    		3、找递推公式
    			找到每次迭代求解相同的部分,并分为固定几步
    		4、判断复杂度
    			时间复杂度或为指数级,需要优化重复计算,缓存重复结果
    二分法
    	https://leetcode-cn.com/leetbook/read/binary-search/xe9cog/
    	模板1
    		69. x 的平方根
    			int相加防溢出: int mid = low + (high - low) / 2;
    			int相乘转为long防溢出:(long)mid * mid  < x
    				注意括号是小写long
    		子主题
    滑动窗口
    	easy
    		187. 重复的DNA序列
    			HashMap
    				子主题
    		209. 长度最小的子数组
    	子主题
    		3.无重复字符的最长子串
    		76.最小覆盖子串
    		438.找到字符串中所有字母异位词
    		567.字符串的排列
    设计
    	1396. 设计地铁系统
    	1797. 设计一个验证系统
    	1845. 座位预约管理系统
    		PriorityQueue
    其他
    	辅助栈解法
    		394. 字符串解码
    			StringBuilder
    				sb.toString()
    			multi = multi * 10 + Integer.parseInt(c + "");
    				multi = multi * 10 + c - '0';
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75

  • 相关阅读:
    【Python从入门到进阶】67、Pandas使用stack和pivot实现数据透视
    如何轻松做好设备巡检管理?
    Ruoyi 从数据库中导出多个excel打包为zip
    计算机视觉:使用opencv实现银行卡号识别
    T Chat 第八期「 龙熠 - 我在大厂做国际化 」8 月 18 日晚 8 点开播
    如何通过C#/VB.NET从PowerPoint文档中提取图片
    极端气候肆虐催化,碳中和带出了一个“再生时代”
    Matlab图像处理-高斯低通滤波器
    windows TBB的使用
    k8s环境生成自签名证书配置secret tls并配置到浏览器
  • 原文地址:https://blog.csdn.net/RiceVan/article/details/128185903