LeetCode刷题笔录Minimum Depth of Binary Tree

从零构建Carsim线控转向仿真:模型搭建、算法集成与整车联动实战 本文详细介绍了从零开始基于Carsim和Simulink搭建线控转向仿真模型的完整实战流程。内容涵盖RWA前轮执行器动力学建模与PID控制、卡尔曼滤波器估算齿条力、HWA方向盘手感模拟算法设计,以及最终实现HWA与RWA闭环联动并进行整车仿真调试。通过分步拆解,帮助读者深入理解线控转向系统的核心原理与工程实现。 阅读详情

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.

和Path Sum这题想法一样,DFS,两个Stack。

/**
 * Definition for binary tree
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public int minDepth(TreeNode root) {
        Stack<TreeNode> nodeStack = new Stack<TreeNode>();
        Stack<Integer> depthStack = new Stack<Integer>();
        if(root == null)
            return 0;
        nodeStack.push(root);
        depthStack.push(1);
        int minDepth = Integer.MAX_VALUE;
        while(!nodeStack.isEmpty()){
            TreeNode node = nodeStack.pop();
            int currDepth = depthStack.pop();
            if(node.left == null && node.right == null){
                if(currDepth < minDepth)
                    minDepth = currDepth;
            }
            if(node.left != null){
                nodeStack.push(node.left);
                depthStack.push(currDepth + 1);
            }
            if(node.right != null){
                nodeStack.push(node.right);
                depthStack.push(currDepth + 1);
            }
        }
        return minDepth;
    }
}


AI量化学习入门指南:从零开始掌握人工智能投资策略 量化投资:利用数学模型和计算机算法进行投资决策的方法算法交易:自动执行预定义交易规则的系统机器学习:让计算机从数据中学习并改进的技术回测:用历史数据检验交易策略表现的过程特征工程:将原始数据转化为模型可理解的输入过拟合:模型过度适应历史数据,导致未来表现不佳夏普比率:衡量单位风险所获得的超额收益AI量化投资不仅仅是技术的应用,更是一种理性、系统化的投资哲学。它不追求预测市场的每一个拐点,而是通过概率思维和风险管理,在不确定性的市场中寻找统计优势。 阅读详情

相关推荐

从‘裸纤’到成品:手把手拆解光纤阵列(FA)的装配、点胶与端面研磨全流程

本文详细拆解了光纤阵列(FA)从裸纤到成品的全流程,包括装配、点胶与端面研磨等关键工艺。通过实战经验和数据对比,揭示了5G基站、数据中心等场景中FA的精密制造要点与常见故障解决方案,为光通信器件生产提供专业指导。

weixin_42652674的博客 745

LeetCode刷题笔录 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo

likecool21的专栏 1万+

3DMax高效建模与人工智能:一场颠覆传统创作的效率革命

AI与3DMax的结合,不仅是工具效率的升级,更是一场创作范式的革命。从“手动雕刻”到“智能共生”,设计师的角色正从执行者转向决策者。正如网友所言:“AI不是替代人类,而是赋予凡人以神笔。”在这场变革中,唯有拥抱技术、深耕创意,方能在数字艺术的浪潮中立于潮头。参考文献与工具推荐技术原理:火星时代资讯《人工智能和三维建模》工具实测:哔哩哔哩《tyDiffusion 3dsMax应用》9、Tripo AI官网教育案例:原创论文《人工智能技术介入三维动画课程建设》

m0_46478534的博客 3009

LeetCode刷题笔录 Two Sum

Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the

likecool21的专栏 1万+

手机抽奖页面代码html,html5大转盘抽奖支持手机转盘抽奖代码

特效描述:html5 大转盘抽奖 支持手机 转盘抽奖代码。html5转盘,html5抽奖,手机转盘,手机抽奖,手机转盘抽奖,可配置奖品抽奖。代码结构1. 引入CSS2. 引入JS3. HTML代码大转盘活动var turnplate={restaraunts:[],//大转盘奖品名称colors:[],//大转盘奖品区块对应背景颜色outsideRadius:192,//大转盘外圆的半径textR...

weixin_39628551的博客 1864

word 2013 长篇文档排版案例教程

office 2013 制作长文格式模板

1万+

LeetCode刷题笔录 Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key.Th

likecool21的专栏 6928

安装了anaconda,pycharm导入numpy时提示没有该包(模块)?

**问题详情:**我安装了anaconda,在利用Pycharm学习numpy这个库的时候,导入numpy这个包的时候提示我没有nummpy这个模块:No module named numpy.如下图所示。 应该说安装了Anaconda,里边就自带了numpy这个库,就应该能够使用。我一个新手怎么搞得懂呢?于是网上查了查找到了一个解决办法,说是我项目的解释器应该设置为Anaconda安装目录下的python.exe,而不应该是系统自带的:https://blog.youkuaiyun.com/aanndd77/art

qq_39820505的博客 1万+

Stanford Algorithms学习:Clustering 2

这是紧接上面的一道题,比较有趣 Question 2 In this question your task is again to run the clustering algorithm from lecture, but on a MUCH bigger graph. So big, in fact, that the distances (i.e., edge costs

likecool21的专栏 2567

[SV]SystemVerilog中,系统函数$cast()的作用是什么?

摘要:SystemVerilog中的$cast()系统函数用于安全的动态类型转换,主要在类层次结构中将父类句柄转换为子类句柄(向下转换)。它通过运行时类型检查确保转换合法性,成功时返回1并赋值句柄,失败则返回0。这种机制使得可以通过父类句柄访问子类特有成员,在多态场景(如UVM验证)中尤为重要。使用时需检查返回值处理转换失败情况。$cast()比静态转换更安全,但不能用于无关类或基本数据类型间的转换。

元直的博客 1210

模拟电路综合笔试题解析

本专栏预计更新60期,当前为第10期,文章约6000字,旨在帮助读者掌握模拟电路笔试的核心知识点与实战技巧。文章分为五个章节,涵盖基础理论、高频考点、大厂题目解析等内容。首先,文章详细解析了DC-DC与LDO的区别及选型依据,并通过真题分析帮助读者理解其应用场景。接着,文章深入探讨了运放电路设计、同步降压电路设计等高频考点,并结合实际案例提供解决方案。此外,文章还分享了特斯拉、华为、大疆等大厂的面试题及解析,帮助读者应对复杂电路设计挑战。最后,文章总结了模拟电路设计中的关键技巧与优化方法,为读者提供全面的笔

启芯硬件的博客 469

Stanford Algorithms学习:Clustering

第二周的第一个编程作业,是利用贪婪算法来实现一个clustering的问题,和ML里学的unsupervised learning差不多。 Question 1 In this programming problem and the next you'll code up the clustering algorithm from lecture for computing a

likecool21的专栏 2507

Cadence OrCAD Capture CIS元器件管理时ERROR(ORCIS-6454): Temporary part number tracking is turned on报错的解决方法

使用Part manager对工程的元器件进行批量管理时,出现如下图所示的ERROR(ORCIS-6454): Temporary part number tracking is turned on报错其解决方法如下。

fydar的博客 3499

LeetCode 刷题笔录 Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

likecool21的专栏 1806

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LeetCode刷题笔录Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:

likecool21的专栏 1296

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

LeetCode刷题笔录 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 这题比较简单

likecool21的专栏 1043

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

LeetCode刷题笔录Unique Binary Search Trees

这里有个讲解(印度人口音真难懂)

likecool21的专栏 1043

LeetCode刷题笔录Container With Most Water

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

likecool21的专栏 1001

LeetCode刷题笔录 Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 随手写的一个,正常的读出每一位的数字然后反序: import java.lang.Math; public class Solution { public int revers

likecool21的专栏 941

LeetCode刷题笔录Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the tota

likecool21的专栏 878

LeetCode刷题笔录Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f

likecool21的专栏 865

LeetCode刷题笔录Convert Sorted Array to Balanced Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这题可以kan'chu'lai

likecool21的专栏 855

求集合的交集/差集

先利用外部排序使两个磁盘文件有序,然后顺序读取两个文件,使用双指针求交集。在进阶 1 中,我们是通过双指针去做的,最坏情况下我们需要完整遍历。时,O(n log m) 可能明显优于 O(n + m)。的,这就使得我们可以通过从 1~1000 遍历来确定交集。,它们已经按非降序排序,请你返回两个数组的。和上一题的区别在于,这里需要找到重复的元素。返回一个数组,数组中的每个元素在。的每个字符串中都出现的共用字符(**注意:**列表中的整数可以按。较小,可以完整加载到内存,而。正整数组成的一个非空数组,按。

jyyyyx的算法之旅 112

LeetCode Hot 100 二叉树专题(二)3 题(Java)

本篇文章共 3 题:543. 二叉树的直径、102. 二叉树的层序遍历、108. 将有序数组转换为二叉搜索树。 每道题都统一按「① 题目分析 & 解题思路 → ② 常见解法(附代码)及讲解 → ③ 知识点总结」的顺序组织;代码使用 Java 编写,节点定义沿用 LeetCode 默认的 TreeNode。

2401_88612756的博客 365

LeetCode 面试经典 150_多维动态规划_交错字符串(97_C++_中等)

LeetCode 面试经典 150_多维动态规划_交错字符串(97_C++_中等) 题目描述: 给定三个字符串 s1、s2、s3,请你帮忙验证 s3 是否是由 s1 和 s2 交错 组成的。 两个字符串 s 和 t 交错 的定义与过程如下,其中每个字符串都会被分割成若干 非空 子字符串: - s = s1 + s2 + ... + sn - t = t1 + t2 + ... + tm - |n - m| <= 1 - 交错 是 s1 + t

huayimenghan的博客 205

LeetCode 每日一题 2026/11/2-2026/11/8

记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步

AlphaTao的博客 175
上一篇: LeetCode刷题笔录Path Sum
下一篇: LeetCode刷题笔录Combinations
likecool21
博客等级 码龄14年 14粉丝 123原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值