当前位置:网站首页>Force buckle day33
Force buckle day33
2022-07-01 18:33:00 【Congruence_ vinegar】
589、N Preorder traversal of a cross tree
Given a n The root node of the fork tree root , return Of its node value The former sequence traversal .n Fork tree In the input sequence traversal serialization representation , Each group of child nodes consists of null values null Separate .

/*
// Definition for a Node.
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, List<Node> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public List<Integer> preorder(Node root) {
List<Integer>list=new ArrayList<>();
pre(root,list);
return list;
}
public void pre(Node root,List<Integer>list){
if(root==null) return ;
list.add(root.val);
for(Node kid:root.children){
pre(kid,list);
}
}
}559、N The maximum depth of the fork tree
Given a N Fork tree , Find its maximum depth .
Maximum depth is the total number of nodes on the longest path from the root node to the farthest leaf node .
N The input of the fork tree is represented by sequence traversal serialization , Each group of child nodes is separated by null values ( See example ).

/*
// Definition for a Node.
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, List<Node> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public int maxDepth(Node root) {
if(root==null) return 0;
int max=0;
for(Node kid:root.children){
int depth=maxDepth(kid);
max=Math.max(max,depth);
}
return max+1;
}
}1380、 The lucky number in the matrix
To give you one m * n Matrix , The number in the matrix Each are not identical . Please press arbitrarily Return all the lucky numbers in the matrix in order .
Lucky number refers to the elements in the matrix that meet the following two conditions at the same time :
- The smallest of all elements in the same row
- The largest of all elements in the same column

Two dimensional array : 3 7 8
9 11 13
15 16 17
The minimum value per line is 3 、9 、15
The maximum value per column is 15、 16 、17
class Solution {
public List<Integer> luckyNumbers (int[][] matrix) {
int m=matrix.length;
int n=matrix[0].length;
int []min=new int[m];
int []max=new int[n];
Arrays.fill(min,Integer.MAX_VALUE);
Arrays.fill(max,Integer.MIN_VALUE);
List<Integer>list=new ArrayList<>();
for(int i=0;i<m;i++){// Traverse the rows of a two-dimensional array
for(int j=0;j<n;j++){// Traverse the columns of a two-dimensional array
min[i]=Math.min(min[i],matrix[i][j]);// Find the minimum value of each row , Fill in the array min in
max[j]=Math.max(max[j],matrix[i][j]);// Find the maximum value of each column , Fill in the array max in
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(matrix[i][j]==min[i]&&matrix[i][j]==max[j]){
list.add(matrix[i][j]);
}
}
}
return list;
}
}边栏推荐
- Cloud computing - make learning easier
- Mujoco XML modeling
- Detailed explanation of select in golang
- SPIE Western optoelectronics exhibition returned offline and successfully held a science and engineering event
- Distributed task queue: Celery usage record
- Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
- Key points on February 15, 2022
- Pytorch crossentropyloss learning
- Data query language (DQL)
- Nielseniq found that 60% of the re launched products had poor returns
猜你喜欢

Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?

. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes

Good looking UI mall source code has been scanned, no back door, no encryption

Calculation of intersection of two line segments

Database - MySQL advanced SQL statement (I)

Penetration practice vulnhub range Tornado

2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers

Fix the black screen caused by iPhone system failure

. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes

Localization through custom services in the shuttle application
随机推荐
Slider verification code identification gadget display
Relationship between sensor size, pixel, dpi resolution, inch and millimeter
Depth first search - DFS (burst search)
Blackwich: the roadmap of decarbonization is the first step to realize the equitable energy transformation in Asia
Blue Bridge Cup real problem: word analysis
When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
[2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
开发那些事儿:EasyCVR平台添加播放地址鉴权
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Blue Bridge Cup real topic: the shortest circuit
MySQL connection tools
Can hero sports go public against the wind?
Subnet division and summary
主成分之综合竞争力案例分析
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Software construction scheme of smart factory collaborative management and control application system
C operator overloads the query table
golang中的select详解
Work and leisure suggestions of old programmers
SCP -i private key usage