加载中...

daily leetcode - path-sum - !

题目地址 https://leetcode.com/problems/path-sum/ 题目描述 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. Note: A leaf is a node with no children. Example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ \ 7 2 1 return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22. 思路 这道题给了一棵二叉树,问是否存在一条从跟结点到叶结点到路径,使得经过到结点值之和为一个给定的 sum 值,这里需要用深度优先算法 DFS 的思想来遍历每一条完整的路....

daily leetcode - minimum-depth-of-binary-tree - !

题目地址 https://leetcode.com/problems/minimum-depth-of-binary-tree/ 题目描述 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its minimum depth = 2. 思路 二叉树的经典问题之最小深度问题就是就最短路径的节点个数,还是用深度优先搜索 DFS 来完成,万能的递归啊。首先判空,若当前结点不存在,直接返回 0。然后看若左子结点不存在,那么对右子结点调用递归函数,并加 1 返回。反之,若右子结点不存在,那么....

基于神经网络的降雨预测

😄 ## 😭 基于神经网络的降雨预测 占坑学习,以后再理解,脑壳痛! 源数据:tianjin.xlsx python 代码: import numpy as np import pandas as pd import sklearn filename = r'tianjin.xlsx' data = pd.read_excel(filename) pd.set_option('display.max_columns',None) # data.head() # data = data.drop('ET0',axis=1)#去除数据集中的ET0 data.head() # 读取前五行数据 len(data) len(data.columns) print(len(data.columns)) data = data.drop(['PMax','ET0', 'Rn', 'Wind', 'PMean', 'TMean', 'Delta','Gama'],axis = 1)#去除不需要的参数 print(data) #data = data.drop(['PMax', 'Wind', 'P....

Dplayer 测试 播放视频

dplayer 测试播放 嘀嘀嘀哒哒哒 老阿姨 注:视频源地址见:https://www.bilibili.com/video/BV1rs411u7K3 上面是分割线 注: 添加代码备注 const dp = new DPlayer({ container: document.getElementById('dplayer'), autoplay: false, theme: '#FADFA3', loop: true, lang: 'zh-cn', screenshot: true, hotkey: true, preload: 'auto', logo: 'logo.png', volume: 0.7, mutex: true, video: { url: 'dplayer.mp4', pic: 'dplayer.png', thumbnails: 'thumbnails.jpg', type: 'auto', }, subtitle: { url: 'dplayer.vtt', type: 'webvtt', fontSize: '25px', bottom: '10....

daily leetcode - balanced-binary-tree - !

题目地址 https://leetcode.com/problems/balanced-binary-tree/ 题目描述 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Example 1: Given the following tree [3,9,20,null,null,15,7]: 3 / \ 9 20 / \ 15 7 Return true. Example 2: Given the following tree [1,2,2,3,3,null,null,4,4]: 1 / \ 2 2 / \ 3 3 / \ 4 4 Return false. 思路 求二叉树是否平衡,根据题目中的定....

daily leetcode - convert-sorted-list-to-binary-search-tree - !

题目地址 https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ 题目描述 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Example: Given the sorted linked list: [-10,-3,0,5,9], One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BS....

daily leetcode - convert-sorted-array-to-binary-search-tree - !

题目地址 https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 题目描述 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Example: Given the sorted array: [-10,-3,0,5,9], One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST: 0 / \ -3 9 / /....

daily leetcode - binary-tree-level-order-traversal-ii - !

题目地址 https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ 题目描述 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ] 思路 从底部层序遍历其实还是从顶部开始遍历,只不过最后存储的方式有所改变,可以参见我之前的博文 Binary Tree Level Order Traversal 关键点解析 代码 解法一: class Solution { public: vector<v....

daily leetcode - construct-binary-tree-from-inorder-and-postorder-traversal - !

题目地址 https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 题目描述 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 思路 这道题要求从中序和后序遍历的结果来重建原二叉树,我们知道中序的遍历顺序是左-根-右,后序的顺序是左-右-根,对于这种树的重建一般都是采用递归来做,可参见我之前的一篇博客Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树。针对这道题,由于后序的顺序的最后一个肯定是根,所以原二叉树的根节点可以知道,题目中给了一个很关键的条件就是树中没有相同元素,有了这个条件我们就可以在中序遍历中也定位出根节点的位置,并以根节点的位置将中序遍历拆分为左右两个部分,分别对其递....

avatar
Lonus Lan
It's better to burn out than to fade away!
公告
暂无更新通知!
最新文章
网站资讯
文章数目 :
156
已运行时间 :
0 天
本站在线访客数 :
1
本站总访问量 :
0