随笔分类 -  leetcode

[Leetcode 111]二叉树的最短深度 BFS/DFS
摘要:题目 给定二叉树,求最短路径包含的节点个数 https://leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minimum depth. The minimum depth is th 阅读全文
posted @ 2021-12-11 02:48 alau 阅读(55) 评论(0) 推荐(0)
[Leetcode 108]有序数组转BST二叉搜索树Convert Sorted Array to Binary Search Tree
摘要:题目 https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ Given an integer array nums where the elements are sorted in ascending or 阅读全文
posted @ 2021-12-05 07:48 alau 阅读(27) 评论(0) 推荐(0)
[Leetcode 22]生成括号generate parentheses
摘要:题目 给定括号对数n,生成所有可能的标准括号结果* *指不能)( https://leetcode.com/problems/generate-parentheses/ Given n pairs of parentheses, write a function to generate all co 阅读全文
posted @ 2021-12-05 06:47 alau 阅读(39) 评论(0) 推荐(0)
[Leetcode 559]N叉树的最大深度Maximum Depth of N-ary Tree DFS/BFS模板
摘要:题目 https://leetcode.com/problems/maximum-depth-of-n-ary-tree/ N叉树的最大深度 Given a n-ary tree, find its maximum depth. The maximum depth is the number of 阅读全文
posted @ 2021-12-04 18:35 alau 阅读(40) 评论(0) 推荐(0)
[Leetcode 701]二叉搜索树BST中插入元素
摘要:题目 BST二叉搜索树中插入元素 二叉搜索树:左边<root<右边 https://leetcode.com/problems/insert-into-a-binary-search-tree/ You are given the root node of a binary search tree 阅读全文
posted @ 2021-12-04 08:10 alau 阅读(73) 评论(0) 推荐(0)
[Leetcode 235/236]LCA二叉树最近公共祖先Lowest Common Ancestor of a Binary Tree
摘要:题目 给定二叉树和两个点,求两点的LCA最近公共祖先 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of L 阅读全文
posted @ 2021-12-04 02:54 alau 阅读(56) 评论(0) 推荐(0)
[Leetcode 98]判断有效的二叉搜索树Validate Binary Search Tree
摘要:题目 https://leetcode.com/problems/validate-binary-search-tree 判断所给二叉树是否是二叉搜索树 二叉搜索树:其值left<root<right *[2,2,2]这种相等的情况也不是搜索树 Given the root of a binary 阅读全文
posted @ 2021-12-03 23:41 alau 阅读(48) 评论(0) 推荐(0)
[Leetcode 104]二叉树最大深度Maximum Depth of Binary Tree
摘要:题目 求二叉树的深度,即根节点出发的最长路径上点的个数,即最长路径+1(本身这个点 https://leetcode.com/problems/maximum-depth-of-binary-tree/ Given the root of a binary tree, return its maxi 阅读全文
posted @ 2021-12-03 17:51 alau 阅读(40) 评论(0) 推荐(0)
[Leetcode 787]中转K站内最便宜机票
摘要:题目 n个城市,想求从src到dist的最廉价机票 有中转站数K的限制,即如果k=5,中转10次机票1000,中转5次机票2000,最后返回2000 There are n cities connected by some number of flights. You are given an ar 阅读全文
posted @ 2021-11-30 07:23 alau 阅读(71) 评论(0) 推荐(0)
[Leetcode 1631]最少体力消耗的路径Path With Minimum Effort
摘要:题目 https://leetcode.com/problems/path-with-minimum-effort/ 每个节点的height不同,矩阵从左上走到右下,求最小体力消耗 当前点体力消耗:max(来的那个节点的effort,|来的那个节点height-当前节点height|) 总最小体力消 阅读全文
posted @ 2021-11-30 06:12 alau 阅读(70) 评论(0) 推荐(0)
[Leetcode 451]*Sort Characters By Frequency优先队列
摘要:题目 Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appe 阅读全文
posted @ 2021-11-30 02:17 alau 阅读(376) 评论(0) 推荐(0)
[Leetcode 692/347]前K个高频词Top K Frequent Words Element
摘要:题目347 https://leetcode.com/problems/top-k-frequent-elements/ 347简单些,692是其变式,多了一种排序 Given an integer array nums and an integer k, return the k most fre 阅读全文
posted @ 2021-11-30 01:41 alau 阅读(32) 评论(0) 推荐(0)
[Leetcode 703]流中第K个最大元素Kth Largest Element in a Stream优先队列239
摘要:题目 找到一串数字中的第K大元素 在原数组的基础上,每次会不断插入元素 插入的同时要返回插入后第K大的元素 https://leetcode.com/problems/kth-largest-element-in-a-stream/ Design a class to find the kth la 阅读全文
posted @ 2021-11-29 04:10 alau 阅读(61) 评论(0) 推荐(0)
[Leetcode 5] 最长回文子串Longest Palindromic Substring
摘要:问题 求最长回文子串,即左右对称 Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Note: "aba" is also a va 阅读全文
posted @ 2021-11-28 06:27 alau 阅读(40) 评论(0) 推荐(0)
[Leetcode 42]雨天积水面积Trapping Rain Water
摘要:题目 下雨天的蓄水量计算 Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after ra 阅读全文
posted @ 2021-11-28 04:54 alau 阅读(54) 评论(0) 推荐(0)
[Leetcode 1041]机器人围成圈 Robot Bounded In Circle
摘要:题目 机器人从(0,0)出发,初始化向北 三种指令 G当前方向+1步,L左转90度,R右转90度 问指令结束后是否成圆圈(只有可能回原点时才成圈) 返回true/false On an infinite plane, a robot initially stands at (0, 0) and fa 阅读全文
posted @ 2021-11-28 00:36 alau 阅读(247) 评论(0) 推荐(0)
[Leetcode 138]复制带随机指针的数列Copy List with Random Pointer
摘要:题目 深复制一个list* Node的结构包含next和random(随机指向节点) 区别 深复制 deep copy Node a=New Node(1) Node b=new Node(1) 复制值 浅复制 shallow copy Node a=new Node(1); Node b=a; 复 阅读全文
posted @ 2021-11-26 21:32 alau 阅读(44) 评论(0) 推荐(0)
[Leetcode 207/210]课程计划Course Schedule I II(BFS)310
摘要:310题目类似,但是数据结构可以选的更简单 恢复内容开始 题目 先修课程和后修课,比如高数离散修完,才能修数据结构 给定numcourse门课程,int[][]的先后计划。int[i][0]为要修的当前课程,int[i][1]为学这门课之前要修的课 207/210都在问:按照int[][],所有课程 阅读全文
posted @ 2021-11-26 05:14 alau 阅读(26) 评论(0) 推荐(0)
[Leetcode 103]二叉树zigzag交叉遍历Binary Tree Zigzag Level Order Traversal
摘要:题目 二叉树zigzag遍历 层次遍历:始终左右 zigzag遍历:每层右左左右交替 Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from 阅读全文
posted @ 2021-11-23 05:34 alau 阅读(108) 评论(0) 推荐(0)
[Leetcode 124]二叉树最大权重路径和 Binary Tree Maximum Path Sum
摘要:题目 与543相似,543是求最长路径,这是最大权重求和(路径不一定最长) A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge con 阅读全文
posted @ 2021-11-23 04:45 alau 阅读(249) 评论(0) 推荐(0)