depth

【LeetCode OJ】Maximum Depth of Binary Tree

杀马特。学长 韩版系。学妹 提交于 2021-02-12 05:49:44
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. /** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { private int max = 0; public void preOrder(TreeNode root, int depth){ if(root == null)return; preOrder(root.left, depth + 1); if(max < depth) max = depth; preOrder(root.right, depth + 1); } public int maxDepth(TreeNode root) { preOrder(root, 1); return max; } } 来源: oschina

Read the depth buffer of OpenGL ES on Android

笑着哭i 提交于 2021-02-11 15:14:44
问题 I am trying to read the depth buffer in OpenGL ES on Android, but all the values are zero. Can someone explain why is that. public void onSurfaceChanged(GL10 unused, int width, int height) { // Adjust the viewport based on geometry changes, // such as screen rotation GLES20.glClearColor(0.0f, 0.0f, 1.0f, 1.0f); GLES20.glClearDepthf(1.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glDepthMask( false ); GLES20

having trouble understanding this code

≡放荡痞女 提交于 2021-01-29 05:45:34
问题 I just started learning recursion and I have an assignment to write a program that tells the nesting depth of a list. Well, I browsed around and found working code to do this, but I'm still having trouble understanding how it works. Here's the code: def depth(L) : nesting = [] for c in L: if type(c) == type(nesting) : nesting.append(depth(c)) if len(nesting) > 0: return 1 + max(nesting) return 1 So naturally, I start to get confused at the line with the append that calls recursion. Does

A circular reference has been detected when serializing the object of class “App\Entity\User” (configured limit: 1)

♀尐吖头ヾ 提交于 2020-11-29 08:45:29
问题 I am faced with a problem that gives me this error: A circular reference has been detected when serializing the object of class "App\Entity\User" (configured limit: 1) I have an Enterprise entity that has mission orders, vehicles, and users. An orders entity that has a relationship with a User, Company, and Vehicle. And a User entity that has a relationship with orders and company. So I have this: Entreprise.php class Entreprise { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type=

IO 延迟与Queue Depth

南笙酒味 提交于 2020-04-08 13:55:25
IO 延迟:存储设备的IO延迟 Queue Depth:磁盘控制器所发出的批量指令的最大条数 IOPS:磁盘设备每秒的IO 三者之间的关系:IOPS=(Queue Depth)/(IO latency) 队列深度描述的是硬盘能够同时激活的最大IO值,队列深度越大,实际性能也会越高。 http://www.cnblogs.com/dreamer-fish/p/3769816.html http://www.bitstech.net/2013/12/28/directio/ http://blog.163.com/bihonggang_anshan/blog/static/131715643201172594757538 http://blog.csdn.net/kidd_3/article/details/6909097 来源: https://www.cnblogs.com/zengkefu/p/5094287.html

Queue depth

南楼画角 提交于 2020-04-08 13:53:49
Queue depth - It is the number of I/O requests that can be kept waiting to be serviced in a port queue. Queue Depth:磁盘控制器所发出的批量指令的最大条数 IOPS:磁盘设备每秒的IO 三者之间的关系:IOPS=(Queue Depth)/(IO latency) 队列深度描述的是硬盘能够同时激活的最大IO值,队列深度越大,实际性能也会越高。 參考資料 ========== https://www.computerweekly.com/feature/Storage-101-Queue-depth-NVMe-and-the-array-controller http://www.cnblogs.com/zengkefu/p/5094287.html http://blog.51cto.com/frankfan/1411753 来源: https://www.cnblogs.com/awpatp/p/8949992.html

[LeetCode] 1111. Maximum Nesting Depth of Two Valid Parentheses Strings

被刻印的时光 ゝ 提交于 2020-04-01 03:48:17
有效括号的嵌套深度。题意是给一个用字符串表示的嵌套括号,请按规则返回这个字符串的 嵌套深度 depth。嵌套深度的定义如下, depth("") = 0 depth(A + B) = max(depth(A), depth(B)) , where A and B are VPS's depth("(" + A + ")") = 1 + depth(A) , where A is a VPS. 例子, Example 1: Input: seq = "(()())" Output: [0,1,1,1,1,0] Example 2: Input: seq = "()(())()" Output: [0,0,0,1,1,0,1,1] 这个题需要用到栈,跟 20题 类似,需要通过判断遍历的是左括号还是右括号来判断深度。 维护一个栈 s,从左至右遍历括号字符串中的每一个字符: 如果当前字符是 (,就把 ( 压入栈中,此时这个 ( 的嵌套深度为栈的高度; 如果当前字符是 ),此时这个 ) 的嵌套深度为栈的高度,随后再从栈中弹出一个 (。 作者:LeetCode-Solution 链接:https://leetcode-cn.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/solution/you-xiao

剑指offer[38]——二叉树的深度

别说谁变了你拦得住时间么 提交于 2020-03-27 12:13:10
题目描述 输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 这个就是采取递归的方法,单独写一个函数,参数是一个节点和该节点所在的深度,每次讲节点改为左右子树节点进行递归,直到节点为空,将此时的深度与目前的最大深度比较取最大值即可。 /* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ function TreeDepth(pRoot) { let depth = 0; if(!pRoot){return depth;} function deepIn(root, l){ if(root){ l++; deepIn(root.left, l); deepIn(root.right, l); }else{ depth = depth>l?depth:l; } } deepIn(pRoot, 0); return depth; } 来源: https://www.cnblogs.com/Jacob98/p/12580271.html

剑指offer:平衡二叉树

风格不统一 提交于 2020-03-17 03:14:19
题目描述 输入一棵二叉树,判断该二叉树是否是平衡二叉树。 方法一 : 递归计算左右子树高度,并且判断左右子树是否也是平衡二叉树。 但这样判断上层结点时会重复遍历下层结点,增加开销。 # -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def IsBalanced_Solution(self, pRoot): # write code here if not pRoot: return True left=self.depth(pRoot.left) right=self.depth(pRoot.right) return abs(left-right)<=1 and self.IsBalanced_Solution(pRoot.left) and self.IsBalanced_Solution(pRoot.right) def depth(self,root): if root==None: return 0 return 1+max(self.depth(root.left),self.depth(root.right)) 方法二 : 如果改为从下往上遍历