leetcode 102 C++AC

leetcode 102
我模仿二叉树的层序遍历的方法,自己写了一个。中间报错了,还特别去看了下这个文章https://blog.csdn.net/weixin_45799835/article/details/105780627
后来发现只是一个小错误,嘻嘻

class Solution {
public:int maxDepth(TreeNode* root) {int dep=0;exp(root,1,dep);return dep;}void exp(TreeNode*root,int c,int &dep){   if(!root) return;if(c>dep)++dep;exp(root->left,c+1,dep);exp(root->right,c+1,dep);}
};

END

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/421191.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

.net动态控件的使用(listview ,treeview,tabControl)

对于控件中显示的数据可能是不固定的。如果固定,数据发生了变化,又要重新设计,这样浪费成本,资源。 所以有用代码操作控件,自由度,可控度高。 1,树控件 //把 tv 作为全局变量 , 这是…

1120. Friend Numbers (20)

1120. Friend Numbers (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueTwo integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, …

泡茶看数据结构-临时(对象设计技术)

一.开场白 第二次《DATA STRUCTURES AND PROBLEM SOVLING WITH C》英文授课,让我产生英文写文章的念头。但是,慢慢开始参合英文吧。一下子写的话,怕写出来博客园首页都不敢收录了。^_^!今天,从课堂和自己下午看总结下,…

分享几个可供学习,休闲的网站

设计的无限可能 http://seeseed.com 包含各种文案,创意短片,各种模板 http://addog.com 微软office plus/ppt 模板之王 http://officeplus.cn 中国数字科技馆 http://cdstm.cn 在线一键抠图 http://remove.bg 全球杂志 http://magazinelib.com 图片…

leetcode 112路径总和

leetcode 112 其实leetcode上的题解和评论都很好的,找题解不用到csdn来,我是想把自己做过的题都记录下来才来写这个 class Solution { public:bool hasPathSum(TreeNode* root,int targetSum) {if(!root) return false;if(root->leftnullptr&&am…

1083. List Grades (25)

1083. List Grades (25) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueGiven a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and outp…

1011. World Cup Betting (20)

1011. World Cup Betting (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueWith the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing b…

.net 日期总结,用于业务时间查询

//今天是这周的第几天,是个英文星期,可以转换成intstring a DateTime.Now.DayOfWeek.ToString();//今天//MessageBox.Show(Convert.ToInt32(DateTime.Now.DayOfWeek) "");昨天MessageBox.Show(DateTime.Now.AddDays(-1).ToString());//星期…

1042. Shuffling Machine (20)

1042. Shuffling Machine (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueShuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid &qu…

leetcode 73 矩阵置零 C++ 两种解法

leetcode 73 两种解法~~&#xff0c;没有一个是我想出来的&#xff0c;哈哈~~ one class Solution { public:void setZeroes(vector<vector<int>>& matrix) {int mmatrix.size(),nmatrix[0].size();bool colfalse,rowfalse;for(int i0;i!m;i){if(!matrix[i][0…

JS第一课

<!DOCTYPE html> <html><head><meta charset"utf-8" /><title></title></head><body><script>///*1,它可以做什么。a, 动态改变页面的内容和页面外观b,验证表单数据&#xff0c;各大网站的注册验证功能可以通…

排序二叉树

排序二叉树 二叉树&#xff1a;作为基本数据结构的一种&#xff0c;是红黑树&#xff0c;B树等树形结构的基础。而排序二叉树是按照二叉树的结构来组织的。在本文中采用链表结构来创建二叉树。排序二叉树的    基本原理&#xff1a; 排序二叉树是将归并排序的基本思想构建二…

1020. Tree Traversals (25)

1020. Tree Traversals (25) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueSuppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to out…

leetcode 387 C++数组做法

leetcode 387 C数组做法 class Solution { public:int firstUniqChar(string s) {int ns.length();if(n0) return -1;int table[26]{0};for(int i0;i!n;i){table[s[i]-a];}for(int i0;i!n;i){if(table[s[i]-a]1)return i;}return -1;} };END

获取Class对象方式

在java中&#xff0c;每个class都有一个相应的Class对象&#xff0c;当编写好一个类&#xff0c;编译完成后&#xff0c;在生成的.class文件中&#xff0c;就产生一个Class对象&#xff0c;用来表示这个类的类型信息。获得Class实例的三种方式&#xff1a; 1). 利用对象调用get…

前端学习(1002):简洁版滑动下拉菜单问题解决

快速滑动 不停切换 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</title><scrip…

js bom and dom

以下的代码只是一些小的例子。我画了一张图来总结js大的结构 <!DOCTYPE html> <html><head><meta charset"UTF-8"><title></title><script>//Point 1 delayer and timer (BOM browser Object Model)var delayer;var tim…

leetcode 383 赎金信 C++

自己想的&#xff0c;一个思路两个解法&#xff0c;从字符串中的第一个唯一字符的思路搬过来的 one class Solution { public:bool canConstruct(string ransomNote, string magazine) {int table2[26]{0};for(int i0;i!magazine.length();i){table2[magazine[i]-a];}for(int …

Win32下 Qt与Lua交互使用(二):在Lua脚本中使用Qt类

话接上篇。成功配置好QtLuatoLua后&#xff0c;我们可以实现在Lua脚本中使用各个Qt的类。直接看代码吧。 #include "include/lua.hpp" #include <QWidget> #include <QApplication> #include <QFile> #include <QDebug>static int tolua_new…